cicboy commited on
Commit
7fb8179
Β·
1 Parent(s): 258e46b

update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -73
app.py CHANGED
@@ -214,75 +214,40 @@ crypto_analysis_crew = Crew(
214
  # ----------------------
215
 
216
  def generate_report(crypto_name, currency, days):
 
 
 
217
  crypto_inputs = {
218
  "cryptocurrency_selection": crypto_name.lower(),
219
  "currency_selection": currency.lower(),
220
  "days_selection": int(days),
221
  }
222
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  result = crypto_analysis_crew.kickoff(inputs=crypto_inputs)
224
 
225
- # Crew returns a dict with final_output
226
  if isinstance(result, dict) and "final_output" in result:
227
- return result["final_output"]
228
-
229
- return str(result)
230
 
231
  # ----------------------
232
  # GRADIO APP
233
  # ----------------------
234
 
235
  with gr.Blocks(theme=gr.themes.Monochrome()) as app:
236
- gr.HTML("""
237
- <style>
238
- #run-btn .rocket{
239
- display: inline-block;
240
- transition: transform 0.2s ease;
241
- }
242
-
243
- #run-btn.loading .rocket {
244
- animation: spin 1s linear infinite;
245
- }
246
-
247
- @keyframes spin {
248
- from { transform: rotate(0deg); }
249
- to { transform: rotate(360deg); }
250
- }
251
- </style>
252
- """)
253
-
254
- # ---- Spinning Rocket JS ----
255
- gr.HTML("""
256
- <script>
257
- function setLoadingState(isLoading) {
258
- const btn = document.getElementById("run-btn");
259
- if (!btn) return;
260
- if (isLoading) {
261
- btn.classList.add("loading");
262
- btn.disabled = true;
263
- } else {
264
- btn.classList.remove("loading");
265
- btn.disabled = false;
266
- }
267
- }
268
-
269
- window.addEventListener("DOMContentLoaded", () => {
270
- const btn = document.getElementById("run-btn");
271
- if (!btn) return;
272
-
273
- btn.addEventListener("click", () => {
274
- setLoadingState(true);
275
- });
276
-
277
- // Detect when output changes β†’ stop spinning
278
- const observer = new MutationObserver(() => {
279
- setLoadingState(false);
280
- });
281
-
282
- observer.observe(document.body, { childList: true, subtree: true });
283
- });
284
- </script>
285
- """)
286
 
287
  gr.Markdown("# πŸͺ™ Crypto Intelligence Dashboard")
288
  gr.Markdown("Run a full multi-agent crypto analysis using structured JSON tools.")
@@ -293,30 +258,16 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as app:
293
  placeholder="Type cryptocurrency name...",
294
  value="bitcoin"
295
  )
296
- currency = gr.Dropdown(
297
- ["usd", "eur", "gbp"],
298
- label="Currency",
299
- value="usd"
300
- )
301
- days = gr.Slider(
302
- minimum=30, maximum=730, value=365, step=15,
303
- label="Historical Lookback (days)"
304
- )
305
 
306
- run_button = gr.Button(
307
- value='<span class="rocket">πŸš€</span> Run Full Analysis',
308
- variant="primary",
309
- elem_id="run-btn",
310
- )
311
 
 
312
  report_output = gr.Markdown(label="πŸ“Š Intelligence Report")
313
 
314
  run_button.click(
315
  generate_report,
316
  inputs=[crypto, currency, days],
317
- outputs=report_output,
318
- show_progress=True
319
  )
320
-
321
- if __name__ == "__main__":
322
- app.launch(server_name="0.0.0.0", server_port=7860)
 
214
  # ----------------------
215
 
216
  def generate_report(crypto_name, currency, days):
217
+ # Yield 0% progress
218
+ yield "⏳ Starting analysis...", None
219
+
220
  crypto_inputs = {
221
  "cryptocurrency_selection": crypto_name.lower(),
222
  "currency_selection": currency.lower(),
223
  "days_selection": int(days),
224
  }
225
 
226
+ # Gradio will animate the progress bar automatically
227
+ for step, update_text in enumerate([
228
+ "Fetching market data...",
229
+ "Fetching historical data...",
230
+ "Fetching sentiment...",
231
+ "Running analytics...",
232
+ "Generating trading strategy...",
233
+ "Producing final market report..."
234
+ ], start=1):
235
+ yield f"πŸ”„ {update_text}", None
236
+
237
+ # Run CrewAI (blocking)
238
  result = crypto_analysis_crew.kickoff(inputs=crypto_inputs)
239
 
240
+ # Final message
241
  if isinstance(result, dict) and "final_output" in result:
242
+ yield "βœ… Analysis complete!", result["final_output"]
243
+ else:
244
+ yield "⚠️ Finished with raw output", str(result)
245
 
246
  # ----------------------
247
  # GRADIO APP
248
  # ----------------------
249
 
250
  with gr.Blocks(theme=gr.themes.Monochrome()) as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
252
  gr.Markdown("# πŸͺ™ Crypto Intelligence Dashboard")
253
  gr.Markdown("Run a full multi-agent crypto analysis using structured JSON tools.")
 
258
  placeholder="Type cryptocurrency name...",
259
  value="bitcoin"
260
  )
261
+ currency = gr.Dropdown(["usd", "eur", "gbp"], label="Currency", value="usd")
262
+ days = gr.Slider(30, 730, value=365, step=15, label="Historical Lookback (days)")
 
 
 
 
 
 
 
263
 
264
+ run_button = gr.Button("πŸš€ Run Full Analysis", variant="primary")
 
 
 
 
265
 
266
+ progress_message = gr.Markdown()
267
  report_output = gr.Markdown(label="πŸ“Š Intelligence Report")
268
 
269
  run_button.click(
270
  generate_report,
271
  inputs=[crypto, currency, days],
272
+ outputs=[progress_message, report_output]
 
273
  )