Spaces:
Sleeping
Sleeping
Commit ·
957f61b
1
Parent(s): 62dbd7b
add app file, requirements and readme
Browse files- .gitignore +207 -0
- LICENSE +21 -0
- README.md +78 -6
- app.py +285 -0
- requirements.txt +6 -0
.gitignore
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[codz]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py.cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# UV
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
#uv.lock
|
| 102 |
+
|
| 103 |
+
# poetry
|
| 104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 106 |
+
# commonly ignored for libraries.
|
| 107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 108 |
+
#poetry.lock
|
| 109 |
+
#poetry.toml
|
| 110 |
+
|
| 111 |
+
# pdm
|
| 112 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 113 |
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
| 114 |
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
| 115 |
+
#pdm.lock
|
| 116 |
+
#pdm.toml
|
| 117 |
+
.pdm-python
|
| 118 |
+
.pdm-build/
|
| 119 |
+
|
| 120 |
+
# pixi
|
| 121 |
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
| 122 |
+
#pixi.lock
|
| 123 |
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
| 124 |
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
| 125 |
+
.pixi
|
| 126 |
+
|
| 127 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 128 |
+
__pypackages__/
|
| 129 |
+
|
| 130 |
+
# Celery stuff
|
| 131 |
+
celerybeat-schedule
|
| 132 |
+
celerybeat.pid
|
| 133 |
+
|
| 134 |
+
# SageMath parsed files
|
| 135 |
+
*.sage.py
|
| 136 |
+
|
| 137 |
+
# Environments
|
| 138 |
+
.env
|
| 139 |
+
.envrc
|
| 140 |
+
.venv
|
| 141 |
+
env/
|
| 142 |
+
venv/
|
| 143 |
+
ENV/
|
| 144 |
+
env.bak/
|
| 145 |
+
venv.bak/
|
| 146 |
+
|
| 147 |
+
# Spyder project settings
|
| 148 |
+
.spyderproject
|
| 149 |
+
.spyproject
|
| 150 |
+
|
| 151 |
+
# Rope project settings
|
| 152 |
+
.ropeproject
|
| 153 |
+
|
| 154 |
+
# mkdocs documentation
|
| 155 |
+
/site
|
| 156 |
+
|
| 157 |
+
# mypy
|
| 158 |
+
.mypy_cache/
|
| 159 |
+
.dmypy.json
|
| 160 |
+
dmypy.json
|
| 161 |
+
|
| 162 |
+
# Pyre type checker
|
| 163 |
+
.pyre/
|
| 164 |
+
|
| 165 |
+
# pytype static type analyzer
|
| 166 |
+
.pytype/
|
| 167 |
+
|
| 168 |
+
# Cython debug symbols
|
| 169 |
+
cython_debug/
|
| 170 |
+
|
| 171 |
+
# PyCharm
|
| 172 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 173 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 174 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 175 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 176 |
+
#.idea/
|
| 177 |
+
|
| 178 |
+
# Abstra
|
| 179 |
+
# Abstra is an AI-powered process automation framework.
|
| 180 |
+
# Ignore directories containing user credentials, local state, and settings.
|
| 181 |
+
# Learn more at https://abstra.io/docs
|
| 182 |
+
.abstra/
|
| 183 |
+
|
| 184 |
+
# Visual Studio Code
|
| 185 |
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
| 186 |
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
| 187 |
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
| 188 |
+
# you could uncomment the following to ignore the entire vscode folder
|
| 189 |
+
# .vscode/
|
| 190 |
+
|
| 191 |
+
# Ruff stuff:
|
| 192 |
+
.ruff_cache/
|
| 193 |
+
|
| 194 |
+
# PyPI configuration file
|
| 195 |
+
.pypirc
|
| 196 |
+
|
| 197 |
+
# Cursor
|
| 198 |
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
| 199 |
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
| 200 |
+
# refer to https://docs.cursor.com/context/ignore-files
|
| 201 |
+
.cursorignore
|
| 202 |
+
.cursorindexingignore
|
| 203 |
+
|
| 204 |
+
# Marimo
|
| 205 |
+
marimo/_static/
|
| 206 |
+
marimo/_lsp/
|
| 207 |
+
__marimo__/
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2025 Jonathan Paserman
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
CHANGED
|
@@ -1,14 +1,86 @@
|
|
| 1 |
---
|
| 2 |
-
title: Powell Assistant
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
-
short_description: Jerome Powell Q&A
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Jerome Powell AI Assistant
|
| 3 |
+
emoji: 🏦
|
| 4 |
+
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
+
short_description: Fine-tuned Phi3-Mini model trained on Jerome Powell's Q&A sessions
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# 🏦 Jerome Powell AI Assistant
|
| 15 |
+
|
| 16 |
+
A specialized AI assistant fine-tuned on Federal Reserve Chairman Jerome Powell's Q&A sessions, built using Microsoft's Phi3-Mini model. Ask questions about monetary policy, economics, and Federal Reserve operations to get responses in Jerome Powell's distinctive style.
|
| 17 |
+
|
| 18 |
+
## 🚀 Features
|
| 19 |
+
|
| 20 |
+
- **Fine-tuned Model**: Based on Microsoft Phi3-Mini, specialized on Jerome Powell's communication style
|
| 21 |
+
- **Interactive Interface**: Clean, modern Gradio interface with advanced settings
|
| 22 |
+
- **Educational Focus**: Designed for learning about Federal Reserve operations and monetary policy
|
| 23 |
+
- **Responsive Design**: Optimized for both desktop and mobile devices
|
| 24 |
+
|
| 25 |
+
## 📊 Model Information
|
| 26 |
+
|
| 27 |
+
- **Base Model**: Microsoft Phi3-Mini
|
| 28 |
+
- **Fine-tuning**: Specialized on Jerome Powell Q&A data
|
| 29 |
+
- **Model Hub**: [BoostedJonP/powell-phi3-mini](https://huggingface.co/BoostedJonP/powell-phi3-mini)
|
| 30 |
+
- **Dataset**: [BoostedJonP/JeromePowell-SFT](https://huggingface.co/datasets/BoostedJonP/JeromePowell-SFT)
|
| 31 |
+
- **Repository**: [BigJonP/powell-phi3-sft](https://github.com/BigJonP/powell-phi3-sft)
|
| 32 |
+
|
| 33 |
+
## 🎯 Usage Examples
|
| 34 |
+
|
| 35 |
+
Try asking questions like:
|
| 36 |
+
- "What factors influence Federal Reserve interest rate decisions?"
|
| 37 |
+
- "How does the Fed balance inflation and employment objectives?"
|
| 38 |
+
- "What is the role of quantitative easing in monetary policy?"
|
| 39 |
+
- "How does the Federal Reserve communicate its policy decisions?"
|
| 40 |
+
|
| 41 |
+
## ⚙️ Advanced Settings
|
| 42 |
+
|
| 43 |
+
The interface includes adjustable parameters:
|
| 44 |
+
- **Max Response Length**: Control the length of generated responses (64-512 tokens)
|
| 45 |
+
- **Number of Beams**: Adjust beam search for quality vs. speed (1-8 beams)
|
| 46 |
+
- **Temperature**: Control creativity and randomness (0.1-2.0)
|
| 47 |
+
|
| 48 |
+
## 🔧 Technical Details
|
| 49 |
+
|
| 50 |
+
### Dependencies
|
| 51 |
+
- `torch>=2.0.0,<2.3.0`
|
| 52 |
+
- `transformers>=4.48.0,<4.50.0`
|
| 53 |
+
- `accelerate>=0.20.0`
|
| 54 |
+
- `bitsandbytes>=0.41.0`
|
| 55 |
+
- `gradio>=4.0.0,<5.0.0`
|
| 56 |
+
- `safetensors>=0.4.0`
|
| 57 |
+
|
| 58 |
+
### Model Loading
|
| 59 |
+
- Uses `@lru_cache` for efficient model loading
|
| 60 |
+
- Optimized for Hugging Face Spaces deployment
|
| 61 |
+
- Automatic device mapping (CUDA/CPU)
|
| 62 |
+
|
| 63 |
+
### Generation Parameters
|
| 64 |
+
- Beam search with configurable beams
|
| 65 |
+
- Temperature-controlled sampling
|
| 66 |
+
- Repetition penalty (1.1)
|
| 67 |
+
- Early stopping enabled
|
| 68 |
+
- Cache optimization
|
| 69 |
+
|
| 70 |
+
## 🚨 Important Disclaimer
|
| 71 |
+
|
| 72 |
+
⚠️ **This AI model provides educational insights based on training data and should not be considered as official Federal Reserve communication or financial advice. Always consult official Fed sources for authoritative information.**
|
| 73 |
+
|
| 74 |
+
## 👨💻 Author
|
| 75 |
+
|
| 76 |
+
- GitHub: [Jonathan Paserman](https://github.com/BigJonP)
|
| 77 |
+
- Model Hub: [BoostedJonP](https://huggingface.co/BoostedJonP)
|
| 78 |
+
|
| 79 |
+
## 📄 License
|
| 80 |
+
|
| 81 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
| 82 |
+
|
| 83 |
+
## 📚 Related Resources
|
| 84 |
+
|
| 85 |
+
- [Jerome Powell Press Release Q&A](https://www.kaggle.com/datasets/jonathanpaserman/fed-press-release-text)
|
| 86 |
+
- [BoostedJonP/JeromePowell-SFT](https://huggingface.co/datasets/BoostedJonP/JeromePowell-SFT)
|
app.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
from functools import lru_cache
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
MODEL_NAME = "BoostedJonP/powell-phi3-mini"
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
logging.basicConfig(level=logging.INFO)
|
| 12 |
+
logger.info("Starting Jerome Powell AI Assistant...")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@lru_cache(maxsize=1)
|
| 16 |
+
def load_model():
|
| 17 |
+
"""Load the fine-tuned Jerome Powell model"""
|
| 18 |
+
logger.info(f"Loading model: {MODEL_NAME}")
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 22 |
+
MODEL_NAME,
|
| 23 |
+
trust_remote_code=True,
|
| 24 |
+
cache_dir="/tmp/model_cache",
|
| 25 |
+
)
|
| 26 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 27 |
+
MODEL_NAME,
|
| 28 |
+
trust_remote_code=True,
|
| 29 |
+
torch_dtype=torch.float16,
|
| 30 |
+
device_map="auto",
|
| 31 |
+
attn_implementation="eager",
|
| 32 |
+
use_cache=True,
|
| 33 |
+
cache_dir="/tmp/model_cache",
|
| 34 |
+
)
|
| 35 |
+
logger.info("Model loaded successfully!")
|
| 36 |
+
except Exception as e:
|
| 37 |
+
logger.error(f"Error loading model: {e}")
|
| 38 |
+
return None, None
|
| 39 |
+
|
| 40 |
+
model.generation_config.use_cache = True
|
| 41 |
+
model.generation_config.pad_token_id = tokenizer.eos_token_id
|
| 42 |
+
|
| 43 |
+
return model, tokenizer
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
model, tokenizer = load_model()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def generate_powell_response(question, max_length=256, num_beams=3, temperature=0.3):
|
| 50 |
+
"""Generate a response in Jerome Powell's style"""
|
| 51 |
+
|
| 52 |
+
if model is None or tokenizer is None:
|
| 53 |
+
return "❌ Model failed to load. Please refresh the page and try again."
|
| 54 |
+
|
| 55 |
+
if not question.strip():
|
| 56 |
+
return (
|
| 57 |
+
"Please ask a question about monetary policy, economics, or Federal Reserve operations."
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
prompt = f"Question: {question.strip()}\nAnswer:"
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
inputs = tokenizer(
|
| 64 |
+
prompt,
|
| 65 |
+
return_tensors="pt",
|
| 66 |
+
truncation=True,
|
| 67 |
+
max_length=256,
|
| 68 |
+
padding=False,
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
if torch.cuda.is_available():
|
| 72 |
+
inputs = {k: v.cuda() for k, v in inputs.items()}
|
| 73 |
+
|
| 74 |
+
with torch.no_grad():
|
| 75 |
+
generation_config = {
|
| 76 |
+
"max_new_tokens": max_length,
|
| 77 |
+
"num_beams": num_beams,
|
| 78 |
+
"early_stopping": True,
|
| 79 |
+
"do_sample": True,
|
| 80 |
+
"temperature": temperature,
|
| 81 |
+
"repetition_penalty": 1.1,
|
| 82 |
+
"use_cache": True,
|
| 83 |
+
"output_scores": False,
|
| 84 |
+
"return_dict_in_generate": False,
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
outputs = model.generate(**inputs, **generation_config)
|
| 88 |
+
|
| 89 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 90 |
+
|
| 91 |
+
if "Answer:" in response:
|
| 92 |
+
answer = response.split("Answer:")[-1].strip()
|
| 93 |
+
else:
|
| 94 |
+
answer = response[len(prompt) :].strip()
|
| 95 |
+
|
| 96 |
+
return (
|
| 97 |
+
answer
|
| 98 |
+
if answer
|
| 99 |
+
else "I apologize, but I couldn't generate a proper response. Please try rephrasing your question."
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
except Exception as e:
|
| 103 |
+
logger.error(f"Error generating response: {e}")
|
| 104 |
+
return f"❌ Error generating response: {str(e)}"
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
custom_css = """
|
| 108 |
+
.gradio-container {
|
| 109 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 110 |
+
max-width: 1200px;
|
| 111 |
+
margin: 0 auto;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.header-text {
|
| 115 |
+
text-align: center;
|
| 116 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 117 |
+
-webkit-background-clip: text;
|
| 118 |
+
-webkit-text-fill-color: transparent;
|
| 119 |
+
background-clip: text;
|
| 120 |
+
font-size: 2.5rem;
|
| 121 |
+
font-weight: bold;
|
| 122 |
+
margin-bottom: 0.5rem;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
.subtitle-text {
|
| 126 |
+
text-align: center;
|
| 127 |
+
color: #666;
|
| 128 |
+
font-size: 1.2rem;
|
| 129 |
+
margin-bottom: 2rem;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.example-box {
|
| 133 |
+
background: #f8f9fa;
|
| 134 |
+
padding: 1rem;
|
| 135 |
+
border-radius: 8px;
|
| 136 |
+
border-left: 4px solid #667eea;
|
| 137 |
+
margin: 1rem 0;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.footer-text {
|
| 141 |
+
text-align: center;
|
| 142 |
+
color: #666;
|
| 143 |
+
font-size: 0.9rem;
|
| 144 |
+
margin-top: 2rem;
|
| 145 |
+
padding: 1rem;
|
| 146 |
+
border-top: 1px solid #eee;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/* Make buttons more prominent */
|
| 150 |
+
.primary-button {
|
| 151 |
+
background: linear-gradient(45deg, #667eea, #764ba2) !important;
|
| 152 |
+
border: none !important;
|
| 153 |
+
color: white !important;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/* Response styling */
|
| 157 |
+
.response-box {
|
| 158 |
+
background: #f8f9fa;
|
| 159 |
+
padding: 1.5rem;
|
| 160 |
+
border-radius: 12px;
|
| 161 |
+
border-left: 4px solid #28a745;
|
| 162 |
+
font-size: 1.1rem;
|
| 163 |
+
line-height: 1.6;
|
| 164 |
+
}
|
| 165 |
+
"""
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def create_interface():
|
| 169 |
+
with gr.Blocks(
|
| 170 |
+
css=custom_css,
|
| 171 |
+
title="Jerome Powell AI Assistant | Federal Reserve Q&A",
|
| 172 |
+
theme=gr.themes.Soft(),
|
| 173 |
+
) as demo:
|
| 174 |
+
|
| 175 |
+
gr.HTML(
|
| 176 |
+
"""
|
| 177 |
+
<div style="display: flex; align-items: center; justify-content: center; gap: 2rem; margin-bottom: 2rem;">
|
| 178 |
+
<div style="flex: 1; text-align: center;">
|
| 179 |
+
<div class="header-text">🏦 Jerome Powell AI Assistant</div>
|
| 180 |
+
<div class="subtitle-text">
|
| 181 |
+
Fine-tuned Phi3-Mini model trained on Federal Reserve Chairman Jerome Powell's Q&A sessions
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
<div style="flex-shrink: 0;">
|
| 185 |
+
<img src="https://storage.googleapis.com/kaggle-datasets-images/8130068/12853913/f5d1487cf839f69edc1fcde3d30a583a/dataset-cover.jpeg?t=2025-08-24-13-28-39"
|
| 186 |
+
alt="Jerome Powell"
|
| 187 |
+
style="width: 200px; height: 200px; border-radius: 50%; object-fit: cover; border: 4px solid #667eea; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
|
| 188 |
+
</div>
|
| 189 |
+
</div>
|
| 190 |
+
"""
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
with gr.Row():
|
| 194 |
+
with gr.Column(scale=2):
|
| 195 |
+
question_input = gr.Textbox(
|
| 196 |
+
label="💬 Ask about monetary policy, economics, or Federal Reserve operations",
|
| 197 |
+
placeholder="e.g., What factors influence Federal Reserve interest rate decisions?",
|
| 198 |
+
lines=3,
|
| 199 |
+
max_lines=5,
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
with gr.Row():
|
| 203 |
+
submit_btn = gr.Button("🎯 Ask Jerome Powell AI", variant="primary", scale=2)
|
| 204 |
+
clear_btn = gr.Button("🔄 Clear", scale=1)
|
| 205 |
+
|
| 206 |
+
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
| 207 |
+
with gr.Row():
|
| 208 |
+
max_length = gr.Slider(
|
| 209 |
+
minimum=64,
|
| 210 |
+
maximum=512,
|
| 211 |
+
value=256,
|
| 212 |
+
step=32,
|
| 213 |
+
label="Max Response Length",
|
| 214 |
+
info="Longer responses may be more detailed but take more time",
|
| 215 |
+
)
|
| 216 |
+
num_beams = gr.Slider(
|
| 217 |
+
minimum=1,
|
| 218 |
+
maximum=8,
|
| 219 |
+
value=3,
|
| 220 |
+
step=1,
|
| 221 |
+
label="Number of Beams",
|
| 222 |
+
info="Higher values = better quality but slower generation (beam search)",
|
| 223 |
+
)
|
| 224 |
+
temperature = gr.Slider(
|
| 225 |
+
minimum=0.1,
|
| 226 |
+
maximum=2.0,
|
| 227 |
+
value=0.3,
|
| 228 |
+
step=0.1,
|
| 229 |
+
label="Temperature",
|
| 230 |
+
info="Higher values = more creative/random responses (affects beam search diversity)",
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
response_output = gr.Textbox(
|
| 234 |
+
label="💼 Jerome Powell AI Response",
|
| 235 |
+
lines=8,
|
| 236 |
+
max_lines=15,
|
| 237 |
+
show_copy_button=True,
|
| 238 |
+
container=True,
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
gr.HTML(
|
| 242 |
+
"""
|
| 243 |
+
<div class="footer-text">
|
| 244 |
+
<h3>📊 Model Information</h3>
|
| 245 |
+
<p>
|
| 246 |
+
<strong>Base Model:</strong> Microsoft Phi3-Mini<br>
|
| 247 |
+
<strong>Fine-tuning:</strong> Specialized on Jerome Powell Q&A data<br>
|
| 248 |
+
<strong>Model Hub:</strong> <a href="https://huggingface.co/BoostedJonP/powell-phi3-mini" target="_blank">BoostedJonP/powell-phi3-mini</a><br>
|
| 249 |
+
<strong>Dataset:</strong> <a href="https://huggingface.co/datasets/BoostedJonP/JeromePowell-SFT" target="_blank">BoostedJonP/JeromePowell-SFT</a><br>
|
| 250 |
+
<strong>Repo:</strong> <a href="https://github.com/BigJonP/powell-phi3-sft" target="_blank">BigJonP/powell-phi3-sft</a><br>
|
| 251 |
+
<strong>Author:</strong> <a href="https://github.com/BigJonPP" target="_blank">Jonathan Paserman</a>
|
| 252 |
+
</p>
|
| 253 |
+
|
| 254 |
+
<p><em>⚠️ Disclaimer: This AI model provides educational insights based on training data and should not be considered as official Federal Reserve communication or financial advice. Always consult official Fed sources for authoritative information.</em></p>
|
| 255 |
+
</div>
|
| 256 |
+
"""
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
submit_btn.click(
|
| 260 |
+
fn=generate_powell_response,
|
| 261 |
+
inputs=[question_input, max_length, num_beams, temperature],
|
| 262 |
+
outputs=response_output,
|
| 263 |
+
show_progress=True,
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
clear_btn.click(lambda: ("", ""), outputs=[question_input, response_output])
|
| 267 |
+
|
| 268 |
+
question_input.submit(
|
| 269 |
+
fn=generate_powell_response,
|
| 270 |
+
inputs=[question_input, max_length, num_beams, temperature],
|
| 271 |
+
outputs=response_output,
|
| 272 |
+
show_progress=True,
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
return demo
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
demo = create_interface()
|
| 279 |
+
|
| 280 |
+
if __name__ == "__main__":
|
| 281 |
+
demo.launch(
|
| 282 |
+
server_name="0.0.0.0",
|
| 283 |
+
server_port=7860,
|
| 284 |
+
show_error=True,
|
| 285 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0.0,<2.3.0
|
| 2 |
+
transformers>=4.48.0,<4.50.0
|
| 3 |
+
accelerate>=0.20.0
|
| 4 |
+
bitsandbytes>=0.41.0
|
| 5 |
+
gradio>=4.0.0,<5.0.0
|
| 6 |
+
safetensors>=0.4.0
|