Spaces:
Running
Running
RobertoBarrosoLuque
commited on
Commit
Β·
f4ca844
1
Parent(s):
8cc0920
Add first version of app
Browse files- .gitignore +2 -0
- requirements.txt +9 -2
- src/app.py +495 -46
.gitignore
CHANGED
|
@@ -225,3 +225,5 @@ uploads/
|
|
| 225 |
downloads/
|
| 226 |
temp/
|
| 227 |
cache/
|
|
|
|
|
|
|
|
|
| 225 |
downloads/
|
| 226 |
temp/
|
| 227 |
cache/
|
| 228 |
+
|
| 229 |
+
.claude
|
requirements.txt
CHANGED
|
@@ -1,2 +1,9 @@
|
|
| 1 |
-
huggingface_hub==0.
|
| 2 |
-
fireworks-ai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub==0.34.3
|
| 2 |
+
fireworks-ai==0.19.18
|
| 3 |
+
gradio==5.41.1
|
| 4 |
+
beautifulsoup4==4.13.4
|
| 5 |
+
lxml==6.0.0
|
| 6 |
+
python-dotenv==1.0.0
|
| 7 |
+
requests==2.31.0
|
| 8 |
+
aiohttp==3.9.5
|
| 9 |
+
aiofiles==23.2.0
|
src/app.py
CHANGED
|
@@ -1,64 +1,513 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
yield response
|
|
|
|
|
|
|
|
|
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
|
|
|
| 43 |
"""
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
"""
|
| 46 |
-
demo = gr.ChatInterface(
|
| 47 |
-
respond,
|
| 48 |
-
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
-
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from typing import List, Dict, Any
|
| 5 |
+
import random
|
| 6 |
+
import os
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from pathlib import Path
|
| 9 |
|
| 10 |
+
load_dotenv()
|
| 11 |
+
_FILE_PATH = Path(__file__).parents[1]
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Mock data for demo purposes
|
| 14 |
+
MOCK_FOMC_MEETINGS = [
|
| 15 |
+
{
|
| 16 |
+
"date": "2024-07-31",
|
| 17 |
+
"title": "Minutes of the Federal Open Market Committee July 30-31, 2024",
|
| 18 |
+
"rate_decision": "5.25-5.50%",
|
| 19 |
+
"summary": "The Committee maintained the federal funds rate target range at 5.25-5.50%. Inflation has eased over the past year but remains elevated."
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"date": "2024-06-12",
|
| 23 |
+
"title": "Minutes of the Federal Open Market Committee June 11-12, 2024",
|
| 24 |
+
"rate_decision": "5.25-5.50%",
|
| 25 |
+
"summary": "The Committee held rates steady as inflation showed signs of cooling but labor market remained robust."
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"date": "2024-05-01",
|
| 29 |
+
"title": "Minutes of the Federal Open Market Committee April 30-May 1, 2024",
|
| 30 |
+
"rate_decision": "5.25-5.50%",
|
| 31 |
+
"summary": "Officials maintained current rates while monitoring inflation progress and employment data."
|
| 32 |
+
}
|
| 33 |
+
]
|
| 34 |
|
| 35 |
+
def simulate_llm_function_call(user_message: str, selected_model: str) -> Dict[str, Any]:
|
| 36 |
+
"""Simulate LLM function calls based on user intent"""
|
| 37 |
+
message_lower = user_message.lower()
|
| 38 |
+
|
| 39 |
+
# Determine which function to call
|
| 40 |
+
if any(word in message_lower for word in ['rate', 'decision', 'interest']):
|
| 41 |
+
return {
|
| 42 |
+
"function": "get_rate_decision",
|
| 43 |
+
"reasoning": [
|
| 44 |
+
"User is asking about interest rate decisions",
|
| 45 |
+
"Analyzing FOMC meeting minutes for rate changes",
|
| 46 |
+
"Extracting rate decisions from recent meetings"
|
| 47 |
+
],
|
| 48 |
+
"result": "Based on the July 2024 FOMC meeting, the federal funds rate was maintained at 5.25-5.50%. This represents no change from the previous meeting in June 2024.",
|
| 49 |
+
"confidence": 0.95,
|
| 50 |
+
"sources": ["FOMC Minutes July 30-31, 2024"]
|
| 51 |
+
}
|
| 52 |
+
elif any(word in message_lower for word in ['compare', 'difference', 'between']):
|
| 53 |
+
return {
|
| 54 |
+
"function": "compare_meetings",
|
| 55 |
+
"reasoning": [
|
| 56 |
+
"User wants to compare different FOMC meetings",
|
| 57 |
+
"Identifying meetings from specified time periods",
|
| 58 |
+
"Analyzing key differences in tone and decisions"
|
| 59 |
+
],
|
| 60 |
+
"result": "Comparing July 2024 vs June 2024 meetings: Both maintained rates at 5.25-5.50%. Key difference: July meeting showed increased confidence in inflation trajectory, while June emphasized continued vigilance.",
|
| 61 |
+
"confidence": 0.88,
|
| 62 |
+
"sources": ["FOMC Minutes July 30-31, 2024", "FOMC Minutes June 11-12, 2024"]
|
| 63 |
+
}
|
| 64 |
+
elif any(word in message_lower for word in ['search', 'find', 'about', 'topic']):
|
| 65 |
+
return {
|
| 66 |
+
"function": "search_topic",
|
| 67 |
+
"reasoning": [
|
| 68 |
+
"User is searching for specific topics in Fed minutes",
|
| 69 |
+
"Performing contextual search across meeting transcripts",
|
| 70 |
+
"Ranking results by relevance and date"
|
| 71 |
+
],
|
| 72 |
+
"result": f"Found relevant discussions about '{user_message}' in recent FOMC meetings. The topic appeared most prominently in discussions about economic outlook and policy considerations.",
|
| 73 |
+
"confidence": 0.82,
|
| 74 |
+
"sources": ["FOMC Minutes July 30-31, 2024", "FOMC Minutes May 1, 2024"]
|
| 75 |
+
}
|
| 76 |
+
else:
|
| 77 |
+
return {
|
| 78 |
+
"function": "general_analysis",
|
| 79 |
+
"reasoning": [
|
| 80 |
+
"Providing general analysis of Fed policy",
|
| 81 |
+
"Drawing from recent FOMC meeting minutes",
|
| 82 |
+
"Contextualizing current monetary policy stance"
|
| 83 |
+
],
|
| 84 |
+
"result": f"Based on recent FOMC meetings, I can help analyze Fed policy. The current federal funds rate is 5.25-5.50%, maintained since July 2023. Recent meetings suggest officials are closely monitoring inflation data while remaining data-dependent on future decisions.",
|
| 85 |
+
"confidence": 0.78,
|
| 86 |
+
"sources": ["Recent FOMC Minutes"]
|
| 87 |
+
}
|
| 88 |
|
| 89 |
+
def format_response_with_reasoning(function_result: Dict[str, Any], model_name: str) -> str:
|
| 90 |
+
"""Format the response with expandable reasoning sections"""
|
| 91 |
+
reasoning_steps = "\n".join([f"β’ {step}" for step in function_result["reasoning"]])
|
| 92 |
+
|
| 93 |
+
response = f"""
|
| 94 |
+
**π Function Called:** `{function_result["function"]}`
|
| 95 |
+
**π€ Model Used:** {model_name}
|
| 96 |
+
**π Confidence:** {function_result["confidence"]:.0%}
|
| 97 |
|
| 98 |
+
**π‘ Analysis Result:**
|
| 99 |
+
{function_result["result"]}
|
| 100 |
|
| 101 |
+
<details>
|
| 102 |
+
<summary><b>π§ Reasoning Chain (Click to expand)</b></summary>
|
| 103 |
|
| 104 |
+
{reasoning_steps}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
**π Sources:**
|
| 107 |
+
{chr(10).join([f"β’ {source}" for source in function_result["sources"]])}
|
| 108 |
+
|
| 109 |
+
</details>
|
| 110 |
+
"""
|
| 111 |
+
return response
|
| 112 |
+
|
| 113 |
+
def respond(
|
| 114 |
+
message: str,
|
| 115 |
+
history: list[tuple[str, str]],
|
| 116 |
+
api_key: str,
|
| 117 |
+
):
|
| 118 |
+
"""Enhanced response function with Fed AI Savant capabilities using OAI OSS 120B"""
|
| 119 |
+
|
| 120 |
+
if not message.strip():
|
| 121 |
+
yield "Please enter a question about Federal Reserve policy or FOMC meetings."
|
| 122 |
+
return
|
| 123 |
+
|
| 124 |
+
if not api_key.strip():
|
| 125 |
+
yield "β Please enter your AI API key in the configuration panel to use the Fed AI Savant."
|
| 126 |
+
return
|
| 127 |
+
|
| 128 |
+
# Fixed model for Fed AI Savant
|
| 129 |
+
model_name = "OAI OSS 120B"
|
| 130 |
+
|
| 131 |
+
# Simulate function call and reasoning
|
| 132 |
+
function_result = simulate_llm_function_call(message, model_name)
|
| 133 |
+
|
| 134 |
+
# Format response with reasoning chain
|
| 135 |
+
formatted_response = format_response_with_reasoning(function_result, model_name)
|
| 136 |
+
|
| 137 |
+
# Simulate streaming response
|
| 138 |
+
response = ""
|
| 139 |
+
for char in formatted_response:
|
| 140 |
+
response += char
|
| 141 |
yield response
|
| 142 |
+
# Small delay to simulate streaming
|
| 143 |
+
import time
|
| 144 |
+
time.sleep(0.01)
|
| 145 |
|
| 146 |
+
def get_fomc_meetings_sidebar():
|
| 147 |
+
"""Generate sidebar content with FOMC meeting details"""
|
| 148 |
+
sidebar_content = "## π Recent FOMC Meetings\n\n"
|
| 149 |
+
|
| 150 |
+
for meeting in MOCK_FOMC_MEETINGS:
|
| 151 |
+
sidebar_content += f"""
|
| 152 |
+
**{meeting['date']}**
|
| 153 |
+
*{meeting['title'][:50]}...*
|
| 154 |
+
- **Rate:** {meeting['rate_decision']}
|
| 155 |
+
- **Summary:** {meeting['summary'][:100]}...
|
| 156 |
|
| 157 |
+
---
|
| 158 |
"""
|
| 159 |
+
return sidebar_content
|
| 160 |
+
|
| 161 |
+
def process_audio_input(audio_file):
|
| 162 |
+
"""Process audio input and convert to text"""
|
| 163 |
+
if audio_file is None:
|
| 164 |
+
return "No audio recorded. Please try again."
|
| 165 |
+
|
| 166 |
+
# Simulate speech-to-text conversion
|
| 167 |
+
# In a real implementation, you'd use libraries like openai-whisper, speech_recognition, etc.
|
| 168 |
+
simulated_transcripts = [
|
| 169 |
+
"What was the federal funds rate decision in the last meeting?",
|
| 170 |
+
"Compare the June and July FOMC meetings",
|
| 171 |
+
"Tell me about inflation expectations",
|
| 172 |
+
"What factors influenced recent policy decisions?",
|
| 173 |
+
"Has the Fed's employment stance changed?"
|
| 174 |
+
]
|
| 175 |
+
|
| 176 |
+
import random
|
| 177 |
+
return random.choice(simulated_transcripts)
|
| 178 |
+
|
| 179 |
+
def text_to_speech(text):
|
| 180 |
+
"""Convert text response to speech"""
|
| 181 |
+
# Simulate text-to-speech functionality
|
| 182 |
+
# In a real implementation, you'd use libraries like pyttsx3, gTTS, or cloud TTS services
|
| 183 |
+
|
| 184 |
+
# Clean the text for better TTS (remove markdown formatting)
|
| 185 |
+
import re
|
| 186 |
+
clean_text = re.sub(r'\*\*.*?\*\*', '', text) # Remove bold markdown
|
| 187 |
+
clean_text = re.sub(r'`.*?`', '', clean_text) # Remove code formatting
|
| 188 |
+
clean_text = re.sub(r'<.*?>', '', clean_text) # Remove HTML tags
|
| 189 |
+
clean_text = re.sub(r'[#β’]', '', clean_text) # Remove special characters
|
| 190 |
+
clean_text = ' '.join(clean_text.split()) # Clean whitespace
|
| 191 |
+
|
| 192 |
+
# For demo purposes, return a message about TTS
|
| 193 |
+
return f"π Text-to-Speech: Would read aloud the response (length: {len(clean_text)} characters)"
|
| 194 |
+
|
| 195 |
+
# Custom CSS for better styling
|
| 196 |
+
custom_css = """
|
| 197 |
+
.gradio-container {
|
| 198 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 199 |
+
}
|
| 200 |
+
.chat-message {
|
| 201 |
+
border-radius: 10px;
|
| 202 |
+
padding: 10px;
|
| 203 |
+
margin: 5px 0;
|
| 204 |
+
}
|
| 205 |
+
.function-call {
|
| 206 |
+
background-color: #f0f8ff;
|
| 207 |
+
border-left: 4px solid #1e88e5;
|
| 208 |
+
padding: 10px;
|
| 209 |
+
margin: 10px 0;
|
| 210 |
+
border-radius: 5px;
|
| 211 |
+
}
|
| 212 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
+
# Model options for dropdown
|
| 215 |
+
MODEL_OPTIONS = [
|
| 216 |
+
"Claude 3.5 Sonnet",
|
| 217 |
+
"GPT-4 Turbo",
|
| 218 |
+
"Llama 3.1 70B",
|
| 219 |
+
"Gemini Pro 1.5",
|
| 220 |
+
"Mixtral 8x7B"
|
| 221 |
+
]
|
| 222 |
+
|
| 223 |
+
# Function to create searchable FOMC meetings accordion
|
| 224 |
+
def create_fomc_meetings_accordion():
|
| 225 |
+
"""Create searchable accordion for FOMC meetings"""
|
| 226 |
+
accordions = []
|
| 227 |
+
for meeting in MOCK_FOMC_MEETINGS:
|
| 228 |
+
title = f"{meeting['date']} - Rate: {meeting['rate_decision']}"
|
| 229 |
+
content = f"""
|
| 230 |
+
**Meeting Title:** {meeting['title']}
|
| 231 |
+
|
| 232 |
+
**Rate Decision:** {meeting['rate_decision']}
|
| 233 |
+
|
| 234 |
+
**Summary:** {meeting['summary']}
|
| 235 |
+
|
| 236 |
+
---
|
| 237 |
+
*Click to expand for full meeting details*
|
| 238 |
+
"""
|
| 239 |
+
accordions.append((title, content))
|
| 240 |
+
return accordions
|
| 241 |
+
|
| 242 |
+
# Create the enhanced interface
|
| 243 |
+
with gr.Blocks(css=custom_css, title="Fed AI Savant", theme=gr.themes.Soft()) as demo:
|
| 244 |
+
|
| 245 |
+
# Row 1: Title and Description
|
| 246 |
+
with gr.Row():
|
| 247 |
+
with gr.Column():
|
| 248 |
+
gr.Markdown("""
|
| 249 |
+
# ποΈ Fed AI Savant
|
| 250 |
+
**Intelligent Analysis of Federal Reserve Policy and FOMC Meetings**
|
| 251 |
+
|
| 252 |
+
Ask questions about interest rate decisions, monetary policy changes, and economic analysis based on Federal Reserve meeting minutes.
|
| 253 |
+
""")
|
| 254 |
+
|
| 255 |
+
# Row 2: API Key Configuration
|
| 256 |
+
with gr.Row():
|
| 257 |
+
with gr.Column(scale=2):
|
| 258 |
+
gr.Markdown("### π Configuration")
|
| 259 |
+
api_key = gr.Textbox(
|
| 260 |
+
label="AI API Key",
|
| 261 |
+
type="password",
|
| 262 |
+
placeholder="Enter your OpenAI, Anthropic, or other AI API key",
|
| 263 |
+
value=os.getenv("OPENAI_API_KEY", ""),
|
| 264 |
+
info="π‘ Your API key is required to analyze Fed policy using AI"
|
| 265 |
+
)
|
| 266 |
+
with gr.Column(scale=3):
|
| 267 |
+
gr.Markdown("### π How to Use")
|
| 268 |
+
gr.Markdown("""
|
| 269 |
+
1. **Enter your AI API key** (OpenAI, Anthropic, etc.)
|
| 270 |
+
2. **Ask questions** about Fed policy, rate decisions, or FOMC meetings
|
| 271 |
+
3. **Review AI reasoning** with expandable explanations and sources
|
| 272 |
+
4. **Use voice input** by clicking the microphone button
|
| 273 |
+
""")
|
| 274 |
+
|
| 275 |
+
# Row 3: FOMC Meetings Accordion (Searchable by Date)
|
| 276 |
+
with gr.Row():
|
| 277 |
+
with gr.Column():
|
| 278 |
+
gr.Markdown("### π Recent FOMC Meeting Minutes")
|
| 279 |
+
|
| 280 |
+
# Date search
|
| 281 |
+
date_search = gr.Textbox(
|
| 282 |
+
placeholder="Search by date (e.g., 2024-07, July 2024)...",
|
| 283 |
+
label="π Search Meetings by Date",
|
| 284 |
+
lines=1
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
# Meetings accordion
|
| 288 |
+
with gr.Accordion("Recent FOMC Meetings", open=False):
|
| 289 |
+
meetings_accordion = gr.HTML("""
|
| 290 |
+
<div style="space-y: 8px;">
|
| 291 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 292 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 293 |
+
π
2024-07-31 - Rate: 5.25-5.50%
|
| 294 |
+
</summary>
|
| 295 |
+
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 296 |
+
<p><strong>Meeting:</strong> Minutes of the Federal Open Market Committee July 30-31, 2024</p>
|
| 297 |
+
<p><strong>Decision:</strong> 5.25-5.50%</p>
|
| 298 |
+
<p><strong>Summary:</strong> The Committee maintained the federal funds rate target range at 5.25-5.50%. Inflation has eased over the past year but remains elevated.</p>
|
| 299 |
+
</div>
|
| 300 |
+
</details>
|
| 301 |
+
|
| 302 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 303 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 304 |
+
π
2024-06-12 - Rate: 5.25-5.50%
|
| 305 |
+
</summary>
|
| 306 |
+
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 307 |
+
<p><strong>Meeting:</strong> Minutes of the Federal Open Market Committee June 11-12, 2024</p>
|
| 308 |
+
<p><strong>Decision:</strong> 5.25-5.50%</p>
|
| 309 |
+
<p><strong>Summary:</strong> The Committee held rates steady as inflation showed signs of cooling but labor market remained robust.</p>
|
| 310 |
+
</div>
|
| 311 |
+
</details>
|
| 312 |
+
|
| 313 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 314 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 315 |
+
π
2024-05-01 - Rate: 5.25-5.50%
|
| 316 |
+
</summary>
|
| 317 |
+
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 318 |
+
<p><strong>Meeting:</strong> Minutes of the Federal Open Market Committee April 30-May 1, 2024</p>
|
| 319 |
+
<p><strong>Decision:</strong> 5.25-5.50%</p>
|
| 320 |
+
<p><strong>Summary:</strong> Officials maintained current rates while monitoring inflation progress and employment data.</p>
|
| 321 |
+
</div>
|
| 322 |
+
</details>
|
| 323 |
+
</div>
|
| 324 |
+
""")
|
| 325 |
+
|
| 326 |
+
# Row 4: Chat Interface with Audio
|
| 327 |
+
with gr.Row():
|
| 328 |
+
with gr.Column():
|
| 329 |
+
gr.Markdown("### π¬ Fed AI Assistant")
|
| 330 |
+
|
| 331 |
+
# Example questions (moved above chat)
|
| 332 |
+
gr.Markdown("### π‘ Example Questions")
|
| 333 |
+
with gr.Row():
|
| 334 |
+
example1 = gr.Button("What was the rate decision in the last FOMC meeting?", variant="secondary", size="sm")
|
| 335 |
+
example2 = gr.Button("Compare June 2024 vs July 2024 FOMC meetings", variant="secondary", size="sm")
|
| 336 |
+
with gr.Row():
|
| 337 |
+
example3 = gr.Button("Tell me about inflation expectations", variant="secondary", size="sm")
|
| 338 |
+
example4 = gr.Button("What factors influenced recent policy decisions?", variant="secondary", size="sm")
|
| 339 |
+
|
| 340 |
+
# Chat interface
|
| 341 |
+
chatbot = gr.Chatbot(
|
| 342 |
+
label="Fed AI Assistant",
|
| 343 |
+
height=400,
|
| 344 |
+
show_label=False,
|
| 345 |
+
avatar_images=(None, None)
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
# Input row with text and audio button (larger text, smaller button)
|
| 349 |
+
with gr.Row():
|
| 350 |
+
with gr.Column(scale=10):
|
| 351 |
+
msg = gr.Textbox(
|
| 352 |
+
placeholder="Ask about Fed policy, rate decisions, or FOMC meetings...",
|
| 353 |
+
label="Your Question",
|
| 354 |
+
lines=2,
|
| 355 |
+
show_label=False
|
| 356 |
+
)
|
| 357 |
+
with gr.Column(scale=1):
|
| 358 |
+
# Audio components
|
| 359 |
+
audio_input = gr.Audio(
|
| 360 |
+
label="ποΈ Voice Input",
|
| 361 |
+
sources=["microphone"],
|
| 362 |
+
type="filepath",
|
| 363 |
+
visible=False
|
| 364 |
+
)
|
| 365 |
+
voice_btn = gr.Button("ποΈ", variant="secondary", size="sm", min_width=40)
|
| 366 |
+
|
| 367 |
+
# Chat functionality
|
| 368 |
+
def user_message(message, history):
|
| 369 |
+
return "", history + [[message, None]]
|
| 370 |
+
|
| 371 |
+
def bot_response(history, api_key_val):
|
| 372 |
+
if history and history[-1][1] is None:
|
| 373 |
+
user_msg = history[-1][0]
|
| 374 |
+
bot_msg = ""
|
| 375 |
+
|
| 376 |
+
# Get the response generator with simplified parameters
|
| 377 |
+
response_gen = respond(user_msg, history[:-1], api_key_val)
|
| 378 |
+
|
| 379 |
+
for partial_response in response_gen:
|
| 380 |
+
bot_msg = partial_response
|
| 381 |
+
history[-1][1] = bot_msg
|
| 382 |
+
yield history
|
| 383 |
+
|
| 384 |
+
msg.submit(
|
| 385 |
+
user_message,
|
| 386 |
+
[msg, chatbot],
|
| 387 |
+
[msg, chatbot],
|
| 388 |
+
queue=False
|
| 389 |
+
).then(
|
| 390 |
+
bot_response,
|
| 391 |
+
[chatbot, api_key],
|
| 392 |
+
chatbot
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
# Voice functionality
|
| 396 |
+
def toggle_audio_input():
|
| 397 |
+
return gr.Audio(visible=True)
|
| 398 |
+
|
| 399 |
+
def handle_audio_input(audio_file):
|
| 400 |
+
if audio_file:
|
| 401 |
+
transcribed_text = process_audio_input(audio_file)
|
| 402 |
+
return transcribed_text, gr.Audio(visible=False)
|
| 403 |
+
return "", gr.Audio(visible=False)
|
| 404 |
+
|
| 405 |
+
def handle_tts(history):
|
| 406 |
+
if history and len(history) > 0 and history[-1][1]:
|
| 407 |
+
last_response = history[-1][1]
|
| 408 |
+
tts_message = text_to_speech(last_response)
|
| 409 |
+
return tts_message
|
| 410 |
+
return "No response to read aloud."
|
| 411 |
+
|
| 412 |
+
# Search functionality for FOMC meetings
|
| 413 |
+
def search_meetings(search_term):
|
| 414 |
+
"""Filter FOMC meetings based on search term"""
|
| 415 |
+
if not search_term.strip():
|
| 416 |
+
# Return all meetings if no search term
|
| 417 |
+
html_content = """
|
| 418 |
+
<div style="space-y: 8px;">
|
| 419 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 420 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 421 |
+
π
2024-07-31 - Rate: 5.25-5.50%
|
| 422 |
+
</summary>
|
| 423 |
+
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 424 |
+
<p><strong>Meeting:</strong> Minutes of the Federal Open Market Committee July 30-31, 2024</p>
|
| 425 |
+
<p><strong>Decision:</strong> 5.25-5.50%</p>
|
| 426 |
+
<p><strong>Summary:</strong> The Committee maintained the federal funds rate target range at 5.25-5.50%. Inflation has eased over the past year but remains elevated.</p>
|
| 427 |
+
</div>
|
| 428 |
+
</details>
|
| 429 |
+
|
| 430 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 431 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 432 |
+
π
2024-06-12 - Rate: 5.25-5.50%
|
| 433 |
+
</summary>
|
| 434 |
+
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 435 |
+
<p><strong>Meeting:</strong> Minutes of the Federal Open Market Committee June 11-12, 2024</p>
|
| 436 |
+
<p><strong>Decision:</strong> 5.25-5.50%</p>
|
| 437 |
+
<p><strong>Summary:</strong> The Committee held rates steady as inflation showed signs of cooling but labor market remained robust.</p>
|
| 438 |
+
</div>
|
| 439 |
+
</details>
|
| 440 |
+
|
| 441 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 442 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 443 |
+
π
2024-05-01 - Rate: 5.25-5.50%
|
| 444 |
+
</summary>
|
| 445 |
+
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 446 |
+
<p><strong>Meeting:</strong> Minutes of the Federal Open Market Committee April 30-May 1, 2024</p>
|
| 447 |
+
<p><strong>Decision:</strong> 5.25-5.50%</p>
|
| 448 |
+
<p><strong>Summary:</strong> Officials maintained current rates while monitoring inflation progress and employment data.</p>
|
| 449 |
+
</div>
|
| 450 |
+
</details>
|
| 451 |
+
</div>
|
| 452 |
+
"""
|
| 453 |
+
else:
|
| 454 |
+
# Filter meetings based on search term
|
| 455 |
+
filtered_meetings = []
|
| 456 |
+
search_lower = search_term.lower()
|
| 457 |
+
|
| 458 |
+
for meeting in MOCK_FOMC_MEETINGS:
|
| 459 |
+
# Search in date, title, or summary
|
| 460 |
+
if (search_lower in meeting['date'].lower() or
|
| 461 |
+
search_lower in meeting['title'].lower() or
|
| 462 |
+
search_lower in meeting['summary'].lower() or
|
| 463 |
+
search_lower in meeting['rate_decision'].lower()):
|
| 464 |
+
filtered_meetings.append(meeting)
|
| 465 |
+
|
| 466 |
+
if filtered_meetings:
|
| 467 |
+
html_content = '<div style="space-y: 8px;">'
|
| 468 |
+
for meeting in filtered_meetings:
|
| 469 |
+
html_content += f"""
|
| 470 |
+
<details style="border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 8px;">
|
| 471 |
+
<summary style="font-weight: 600; cursor: pointer; color: #1f2937;">
|
| 472 |
+
π
{meeting['date']} - Rate: {meeting['rate_decision']}
|
| 473 |
+
</summary>
|
| 474 |
+
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #e5e7eb;">
|
| 475 |
+
<p><strong>Meeting:</strong> {meeting['title']}</p>
|
| 476 |
+
<p><strong>Decision:</strong> {meeting['rate_decision']}</p>
|
| 477 |
+
<p><strong>Summary:</strong> {meeting['summary']}</p>
|
| 478 |
+
</div>
|
| 479 |
+
</details>
|
| 480 |
+
"""
|
| 481 |
+
html_content += '</div>'
|
| 482 |
+
else:
|
| 483 |
+
html_content = f'<p style="color: #6b7280; text-align: center; padding: 20px;">No meetings found matching "{search_term}"</p>'
|
| 484 |
+
|
| 485 |
+
return html_content
|
| 486 |
+
|
| 487 |
+
# Wire up search functionality
|
| 488 |
+
date_search.change(
|
| 489 |
+
search_meetings,
|
| 490 |
+
inputs=date_search,
|
| 491 |
+
outputs=meetings_accordion
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
# Wire up voice buttons
|
| 495 |
+
voice_btn.click(
|
| 496 |
+
toggle_audio_input,
|
| 497 |
+
outputs=audio_input
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
audio_input.change(
|
| 501 |
+
handle_audio_input,
|
| 502 |
+
inputs=audio_input,
|
| 503 |
+
outputs=[msg, audio_input]
|
| 504 |
+
)
|
| 505 |
+
|
| 506 |
+
# Wire up example question buttons
|
| 507 |
+
example1.click(lambda: "What was the rate decision in the last FOMC meeting?", outputs=msg)
|
| 508 |
+
example2.click(lambda: "Compare June 2024 vs July 2024 FOMC meetings", outputs=msg)
|
| 509 |
+
example3.click(lambda: "Tell me about inflation expectations", outputs=msg)
|
| 510 |
+
example4.click(lambda: "What factors influenced recent policy decisions?", outputs=msg)
|
| 511 |
|
| 512 |
if __name__ == "__main__":
|
| 513 |
demo.launch()
|