Update app.py
Browse files
app.py
CHANGED
@@ -185,6 +185,30 @@ def market_analysis_agent(user_input, history=[]):
|
|
185 |
except Exception as e:
|
186 |
return [(user_input, f"Oops, something went wrong: {str(e)}")], history
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
# Gradio Interface setup
|
189 |
chat_interface = gr.Interface(
|
190 |
fn=market_analysis_agent, # Function for handling user interaction
|
|
|
185 |
except Exception as e:
|
186 |
return [(user_input, f"Oops, something went wrong: {str(e)}")], history
|
187 |
|
188 |
+
def fetch_crypto_trends(symbol="BTC", market="USD", api_key="your_api_key_here"):
|
189 |
+
url = f'https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_DAILY&symbol={symbol}&market={market}&apikey={api_key}'
|
190 |
+
try:
|
191 |
+
response = requests.get(url)
|
192 |
+
response.raise_for_status() # Raise exception for HTTP errors
|
193 |
+
data = response.json()
|
194 |
+
if "Time Series (Digital Currency Daily)" in data:
|
195 |
+
trends = data["Time Series (Digital Currency Daily)"]
|
196 |
+
latest_date = max(trends.keys()) # Get the most recent date
|
197 |
+
latest_data = trends[latest_date]
|
198 |
+
return {
|
199 |
+
"date": latest_date,
|
200 |
+
"open": latest_data["1a. open (USD)"],
|
201 |
+
"high": latest_data["2a. high (USD)"],
|
202 |
+
"low": latest_data["3a. low (USD)"],
|
203 |
+
"close": latest_data["4a. close (USD)"],
|
204 |
+
"volume": latest_data["5. volume"],
|
205 |
+
"market_cap": latest_data["6. market cap (USD)"]
|
206 |
+
}
|
207 |
+
else:
|
208 |
+
return "No cryptocurrency data available. Check your API key or query parameters."
|
209 |
+
except Exception as e:
|
210 |
+
return f"Error fetching cryptocurrency trends: {str(e)}"
|
211 |
+
|
212 |
# Gradio Interface setup
|
213 |
chat_interface = gr.Interface(
|
214 |
fn=market_analysis_agent, # Function for handling user interaction
|