Spaces:
Running
Running
RobertoBarrosoLuque
commited on
Commit
Β·
6e9984b
1
Parent(s):
e1c9d7f
Cleanup frontend
Browse files- src/app.py +106 -122
- src/modules/utils.py +3 -1
src/app.py
CHANGED
|
@@ -90,134 +90,119 @@ def create_fomc_meetings_accordion():
|
|
| 90 |
accordions.append((title, content))
|
| 91 |
return accordions
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
with gr.Blocks(css=_CUSTOM_CSS, title="Fed AI Savant", theme=gr.themes.Soft()) as demo:
|
| 95 |
-
|
| 96 |
-
# Row 1: Title and Description
|
| 97 |
-
with gr.Row():
|
| 98 |
-
with gr.Column():
|
| 99 |
-
gr.Markdown("""
|
| 100 |
-
# ποΈ Fed AI Savant ποΈ
|
| 101 |
-
**Intelligent Analysis of Federal Reserve Policy and FOMC Meetings**
|
| 102 |
-
|
| 103 |
-
Ask questions about interest rate decisions, monetary policy changes, and economic analysis based on Federal Reserve meeting minutes.
|
| 104 |
-
""")
|
| 105 |
-
|
| 106 |
-
# Row 2: API Key Configuration
|
| 107 |
-
with gr.Row():
|
| 108 |
-
with gr.Column(scale=1):
|
| 109 |
-
gr.Markdown("### Powered by")
|
| 110 |
-
gr.Image(
|
| 111 |
-
value=str(_FILE_PATH / "assets" / "fireworks_logo.png"),
|
| 112 |
-
height=60,
|
| 113 |
-
width=200,
|
| 114 |
-
show_label=False,
|
| 115 |
-
show_download_button=False,
|
| 116 |
-
container=False,
|
| 117 |
-
show_fullscreen_button=False,
|
| 118 |
-
show_share_button=False,
|
| 119 |
-
)
|
| 120 |
-
with gr.Column(scale=1):
|
| 121 |
-
gr.Markdown("## βοΈ Configuration")
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
api_key_value = gr.Textbox(
|
| 126 |
-
label="Fireworks AI API Key",
|
| 127 |
-
type="password",
|
| 128 |
-
placeholder="Enter your Fireworks AI API key",
|
| 129 |
-
value=val,
|
| 130 |
-
info="Required for AI processing",
|
| 131 |
-
)
|
| 132 |
-
with gr.Column(scale=2):
|
| 133 |
-
gr.Markdown("### π How to Use")
|
| 134 |
-
gr.Markdown("""
|
| 135 |
-
1. **Enter your AI API key**
|
| 136 |
-
2. **Ask questions** about Fed policy, rate decisions, or FOMC meetings
|
| 137 |
-
3. **Review AI reasoning** with expandable explanations and sources
|
| 138 |
-
""")
|
| 139 |
-
|
| 140 |
-
# Row 3: FOMC Meetings Accordion (Searchable by Date)
|
| 141 |
with gr.Row():
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
| 145 |
# Date search
|
| 146 |
date_search = gr.Textbox(
|
| 147 |
-
placeholder="Search by date
|
| 148 |
-
label="π Search
|
| 149 |
-
lines=1
|
|
|
|
| 150 |
)
|
| 151 |
-
|
| 152 |
-
with gr.Accordion("FOMC Meetings", open=False):
|
| 153 |
-
def generate_meetings_html(meetings_list):
|
| 154 |
-
"""Generate HTML for meetings list"""
|
| 155 |
-
if not meetings_list:
|
| 156 |
-
return '<p style="color: #6b7280; text-align: center; padding: 20px;">No meetings available</p>'
|
| 157 |
-
|
| 158 |
-
html_content = '<div style="space-y: 8px;">'
|
| 159 |
-
for meeting in meetings_list:
|
| 160 |
-
date = meeting.get('date', 'Unknown Date')
|
| 161 |
-
rate_decision = meeting.get('rate_decision', 'N/A')
|
| 162 |
-
title = meeting.get('title', 'FOMC Meeting')
|
| 163 |
-
action = meeting.get('action', 'N/A')
|
| 164 |
-
magnitude = meeting.get('magnitude', 'N/A')
|
| 165 |
-
summary = meeting.get('summary', 'No summary available')
|
| 166 |
-
economic_outlook = meeting.get('economic_outlook', 'N/A')
|
| 167 |
-
market_impact = meeting.get('market_impact', 'N/A')
|
| 168 |
-
url = meeting.get('url', '')
|
| 169 |
-
|
| 170 |
-
factors_html = ""
|
| 171 |
-
key_factors = meeting.get('key_economic_factors', [])
|
| 172 |
-
if key_factors and len(key_factors) > 0:
|
| 173 |
-
factors_html = "<p><strong>Key Factors:</strong></p><ul>"
|
| 174 |
-
for factor in key_factors:
|
| 175 |
-
factors_html += f"<li>{factor}</li>"
|
| 176 |
-
factors_html += "</ul>"
|
| 177 |
-
|
| 178 |
-
html_content += f"""
|
| 179 |
-
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 180 |
-
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 181 |
-
π
{date} - Rate: {rate_decision}
|
| 182 |
-
</summary>
|
| 183 |
-
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 184 |
-
<p><strong>Meeting:</strong> {title}</p>
|
| 185 |
-
<p><strong>Action:</strong> {action}</p>
|
| 186 |
-
<p><strong>Rate:</strong> {rate_decision}</p>
|
| 187 |
-
<p><strong>Magnitude:</strong> {magnitude}</p>
|
| 188 |
-
<p><strong>Forward Guidance:</strong> {summary}</p>
|
| 189 |
-
{factors_html}
|
| 190 |
-
<p><strong>Economic Outlook:</strong> {economic_outlook}</p>
|
| 191 |
-
<p><strong>Market Impact:</strong> {market_impact}</p>
|
| 192 |
-
{f'<p><strong>Source:</strong> <a href="{url}" target="_blank">Fed Minutes PDF</a></p>' if url else ''}
|
| 193 |
-
</div>
|
| 194 |
-
</details>
|
| 195 |
-
"""
|
| 196 |
-
html_content += '</div>'
|
| 197 |
-
return html_content
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
gr.Markdown("### π¬ Fed AI Assistant")
|
|
|
|
| 216 |
|
| 217 |
chat_interface = gr.ChatInterface(
|
| 218 |
fn=respond_for_chat_interface,
|
| 219 |
type="messages",
|
| 220 |
-
chatbot=gr.Chatbot(height=
|
| 221 |
textbox=gr.Textbox(
|
| 222 |
placeholder="Ask about Fed policy, rate decisions, or FOMC meetings...", scale=10
|
| 223 |
),
|
|
@@ -225,16 +210,15 @@ with gr.Blocks(css=_CUSTOM_CSS, title="Fed AI Savant", theme=gr.themes.Soft()) a
|
|
| 225 |
cache_examples=False,
|
| 226 |
submit_btn="Send",
|
| 227 |
)
|
|
|
|
|
|
|
| 228 |
with gr.Row():
|
| 229 |
with gr.Column(scale=1):
|
| 230 |
-
example_1 = gr.Button(_EXAMPLES[0], size="
|
| 231 |
-
example_2= gr.Button(
|
| 232 |
-
_EXAMPLES[1], size="md"
|
| 233 |
-
)
|
| 234 |
with gr.Column(scale=1):
|
| 235 |
-
example_3 = gr.Button(_EXAMPLES[2], size="
|
| 236 |
-
example_4 = gr.Button(_EXAMPLES[3], size="
|
| 237 |
-
|
| 238 |
|
| 239 |
date_search.change(
|
| 240 |
search_and_format_meetings,
|
|
|
|
| 90 |
accordions.append((title, content))
|
| 91 |
return accordions
|
| 92 |
|
| 93 |
+
def generate_meetings_html(meetings_list):
|
| 94 |
+
"""Generate HTML for meetings list"""
|
| 95 |
+
if not meetings_list:
|
| 96 |
+
return '<p style="color: #6b7280; text-align: center; padding: 20px;">No meetings available</p>'
|
| 97 |
+
|
| 98 |
+
html_content = '<div style="max-height: 600px; overflow-y: auto;">'
|
| 99 |
+
for meeting in meetings_list:
|
| 100 |
+
date = meeting.get('date', 'Unknown Date')
|
| 101 |
+
rate_decision = meeting.get('rate', 'N/A')
|
| 102 |
+
title = meeting.get('title', 'FOMC Meeting')
|
| 103 |
+
action = meeting.get('action', 'N/A')
|
| 104 |
+
magnitude = meeting.get('magnitude', 'N/A')
|
| 105 |
+
forward_guidance = meeting.get('forward_guidance')
|
| 106 |
+
economic_outlook = meeting.get('economic_outlook')
|
| 107 |
+
market_impact = meeting.get('market_impact', 'N/A')
|
| 108 |
+
url = meeting.get('url', '')
|
| 109 |
+
|
| 110 |
+
factors_html = ""
|
| 111 |
+
key_factors = meeting.get('key_economic_factors', [])
|
| 112 |
+
if key_factors and len(key_factors) > 0:
|
| 113 |
+
factors_html = "<p style='margin: 8px 0; font-size: 0.9em;'><strong>Key Factors:</strong></p><ul style='margin: 4px 0; padding-left: 20px; font-size: 0.85em;'>"
|
| 114 |
+
for factor in key_factors:
|
| 115 |
+
factors_html += f"<li style='margin: 2px 0;'>{factor}</li>"
|
| 116 |
+
factors_html += "</ul>"
|
| 117 |
+
|
| 118 |
+
html_content += f"""
|
| 119 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 10px; margin-bottom: 10px; background: white;">
|
| 120 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937; font-size: 0.95em;">
|
| 121 |
+
π
{date} - {rate_decision}
|
| 122 |
+
</summary>
|
| 123 |
+
<div style="margin-top: 10px; padding-top: 10px; border-top: 1px solid #e5e7eb; font-size: 0.85em;">
|
| 124 |
+
<p style="margin: 4px 0;"><strong>Action:</strong> {action}</p>
|
| 125 |
+
<p style="margin: 4px 0;"><strong>Magnitude:</strong> {magnitude}</p>
|
| 126 |
+
<p style="margin: 8px 0;"><strong>Forward Guidance:</strong> {forward_guidance}</p>
|
| 127 |
+
{factors_html}
|
| 128 |
+
<p style="margin: 8px 0;"><strong>Economic Outlook:</strong> {economic_outlook}</p>
|
| 129 |
+
<p style="margin: 8px 0;"><strong>Market Impact:</strong> {market_impact}</p>
|
| 130 |
+
{f'<p style="margin: 8px 0;"><strong>Source:</strong> <a href="{url}" target="_blank" style="color: #1e88e5;">Fed Minutes PDF</a></p>' if url else ''}
|
| 131 |
+
</div>
|
| 132 |
+
</details>
|
| 133 |
+
"""
|
| 134 |
+
html_content += '</div>'
|
| 135 |
+
return html_content
|
| 136 |
+
|
| 137 |
+
def search_and_format_meetings(query: str):
|
| 138 |
+
"""Search meetings and format them for HTML display"""
|
| 139 |
+
if not query.strip():
|
| 140 |
+
return generate_meetings_html(FOMC_MEETINGS)
|
| 141 |
+
|
| 142 |
+
search_result = search_meetings_by_date(query)
|
| 143 |
+
|
| 144 |
+
if search_result.get("success") and search_result.get("results"):
|
| 145 |
+
return generate_meetings_html(search_result["results"])
|
| 146 |
+
else:
|
| 147 |
+
return '<p style="color: #ef4444; text-align: center; padding: 20px;">No meetings found matching your search.</p>'
|
| 148 |
+
|
| 149 |
with gr.Blocks(css=_CUSTOM_CSS, title="Fed AI Savant", theme=gr.themes.Soft()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
gr.Markdown("""
|
| 152 |
+
# ποΈ Fed AI Savant
|
| 153 |
+
**Intelligent Analysis of Federal Reserve Policy
|
| 154 |
+
and FOMC Meetings with [gpt-oss 120B](https://huggingface.co/openai/gpt-oss-120b)**
|
| 155 |
+
""")
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
with gr.Row():
|
| 158 |
+
# Sidebar for FOMC Meetings
|
| 159 |
+
with gr.Column(scale=1, min_width=300):
|
| 160 |
+
gr.Markdown("### π FOMC Meetings")
|
| 161 |
+
|
| 162 |
# Date search
|
| 163 |
date_search = gr.Textbox(
|
| 164 |
+
placeholder="Search by date...",
|
| 165 |
+
label="π Search",
|
| 166 |
+
lines=1,
|
| 167 |
+
container=False
|
| 168 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
+
meetings_accordion = gr.HTML(generate_meetings_html(FOMC_MEETINGS))
|
| 171 |
+
|
| 172 |
+
# Main content area
|
| 173 |
+
with gr.Column(scale=2):
|
| 174 |
+
# API Key Configuration
|
| 175 |
+
with gr.Row():
|
| 176 |
+
with gr.Column(scale=1):
|
| 177 |
+
gr.Markdown("### Powered by")
|
| 178 |
+
gr.Image(
|
| 179 |
+
value=str(_FILE_PATH / "assets" / "fireworks_logo.png"),
|
| 180 |
+
height=60,
|
| 181 |
+
width=200,
|
| 182 |
+
show_label=False,
|
| 183 |
+
show_download_button=False,
|
| 184 |
+
container=False,
|
| 185 |
+
show_fullscreen_button=False,
|
| 186 |
+
show_share_button=False,
|
| 187 |
+
)
|
| 188 |
+
with gr.Column(scale=2):
|
| 189 |
+
val = os.getenv("FIREWORKS_API_KEY", "")
|
| 190 |
+
api_key_value = gr.Textbox(
|
| 191 |
+
label="βοΈ Fireworks AI API Key",
|
| 192 |
+
type="password",
|
| 193 |
+
placeholder="Enter your API key",
|
| 194 |
+
value=val,
|
| 195 |
+
info="Required for AI processing",
|
| 196 |
+
container=True
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
gr.Markdown("### π¬ Fed AI Assistant")
|
| 200 |
+
gr.Markdown("Ask questions about Fed policy, rate decisions, or FOMC meetings")
|
| 201 |
|
| 202 |
chat_interface = gr.ChatInterface(
|
| 203 |
fn=respond_for_chat_interface,
|
| 204 |
type="messages",
|
| 205 |
+
chatbot=gr.Chatbot(height=500, show_label=False, type="messages"),
|
| 206 |
textbox=gr.Textbox(
|
| 207 |
placeholder="Ask about Fed policy, rate decisions, or FOMC meetings...", scale=10
|
| 208 |
),
|
|
|
|
| 210 |
cache_examples=False,
|
| 211 |
submit_btn="Send",
|
| 212 |
)
|
| 213 |
+
|
| 214 |
+
gr.Markdown("### π‘ Example Questions")
|
| 215 |
with gr.Row():
|
| 216 |
with gr.Column(scale=1):
|
| 217 |
+
example_1 = gr.Button(_EXAMPLES[0], size="sm")
|
| 218 |
+
example_2 = gr.Button(_EXAMPLES[1], size="sm")
|
|
|
|
|
|
|
| 219 |
with gr.Column(scale=1):
|
| 220 |
+
example_3 = gr.Button(_EXAMPLES[2], size="sm")
|
| 221 |
+
example_4 = gr.Button(_EXAMPLES[3], size="sm")
|
|
|
|
| 222 |
|
| 223 |
date_search.change(
|
| 224 |
search_and_format_meetings,
|
src/modules/utils.py
CHANGED
|
@@ -25,8 +25,10 @@ def create_meeting_list(meeting_data: list) -> list[dict]:
|
|
| 25 |
{
|
| 26 |
"date": meeting.get("date", ""),
|
| 27 |
"title": meeting.get("title", ""),
|
|
|
|
| 28 |
"rate_decision": meeting.get("rate", ""),
|
| 29 |
-
"summary": meeting.get("forward_guidance", ""),
|
|
|
|
| 30 |
"action": meeting.get("action", ""),
|
| 31 |
"magnitude": meeting.get("magnitude", ""),
|
| 32 |
"key_economic_factors": meeting.get("key_economic_factors", []),
|
|
|
|
| 25 |
{
|
| 26 |
"date": meeting.get("date", ""),
|
| 27 |
"title": meeting.get("title", ""),
|
| 28 |
+
"rate": meeting.get("rate", ""),
|
| 29 |
"rate_decision": meeting.get("rate", ""),
|
| 30 |
+
"summary": meeting.get("forward_guidance", ""),
|
| 31 |
+
"forward_guidance": meeting.get("forward_guidance", ""),
|
| 32 |
"action": meeting.get("action", ""),
|
| 33 |
"magnitude": meeting.get("magnitude", ""),
|
| 34 |
"key_economic_factors": meeting.get("key_economic_factors", []),
|