s1123725 commited on
Commit
41ee4c4
·
verified ·
1 Parent(s): 06e563f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -2,7 +2,6 @@ import os
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
- import re
6
 
7
  # ===========================
8
  # Constants
@@ -10,7 +9,7 @@ import re
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  # ===========================
13
- # GAIA Agent Logic (65% version)
14
  # ===========================
15
  class HybridAgent65:
16
  def __init__(self):
@@ -41,17 +40,6 @@ class HybridAgent65:
41
 
42
  # Fallback
43
  def fallback(self, q):
44
- q_lower = q.lower()
45
- if any(op in q for op in ['+', '-', '*', '/']):
46
- nums = [float(n) for n in re.findall(r'-?\d+\.?\d*', q)[:2]]
47
- if len(nums) == 2:
48
- if '+' in q: return str(int(nums[0]+nums[1]))
49
- if '-' in q: return str(int(nums[0]-nums[1]))
50
- if '*' in q: return str(int(nums[0]*nums[1]))
51
- if '/' in q: return str(nums[0]/nums[1])
52
- if 'how many' in q_lower:
53
- numbers = re.findall(r'\b\d+\b', q)
54
- return numbers[-1] if numbers else "2"
55
  return "Unknown"
56
 
57
  def __call__(self, question):
@@ -64,11 +52,12 @@ class HybridAgent65:
64
  # Run & Submit
65
  # ===========================
66
  def run_and_submit_all(profile_state):
 
67
  profile = profile_state.value if isinstance(profile_state, gr.State) else profile_state
68
  if not profile:
69
  return "❌ Please login with your Hugging Face account.", None
70
 
71
- username = profile["username"] if isinstance(profile, dict) else profile.username
72
  space_id = os.getenv("SPACE_ID", "unknown")
73
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
74
 
@@ -113,7 +102,7 @@ def run_and_submit_all(profile_state):
113
  return f"❌ Submission failed: {e}", pd.DataFrame(results_log)
114
 
115
  # ===========================
116
- # Gradio Interface (stable for HF login)
117
  # ===========================
118
  with gr.Blocks() as demo:
119
  gr.Markdown("# 🎯 Hybrid GAIA Agent (65% Version)")
@@ -129,7 +118,7 @@ with gr.Blocks() as demo:
129
  # State to store HF profile
130
  user_state = gr.State()
131
 
132
- # LoginButton stores profile into state
133
  login_btn = gr.LoginButton()
134
  login_btn.click(lambda p: p, inputs=[login_btn], outputs=[user_state])
135
 
 
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
 
5
 
6
  # ===========================
7
  # Constants
 
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # ===========================
12
+ # GAIA Agent (65% version)
13
  # ===========================
14
  class HybridAgent65:
15
  def __init__(self):
 
40
 
41
  # Fallback
42
  def fallback(self, q):
 
 
 
 
 
 
 
 
 
 
 
43
  return "Unknown"
44
 
45
  def __call__(self, question):
 
52
  # Run & Submit
53
  # ===========================
54
  def run_and_submit_all(profile_state):
55
+ # profile_state 存了 HF profile
56
  profile = profile_state.value if isinstance(profile_state, gr.State) else profile_state
57
  if not profile:
58
  return "❌ Please login with your Hugging Face account.", None
59
 
60
+ username = profile["username"] if isinstance(profile, dict) else getattr(profile, "username", "local_user")
61
  space_id = os.getenv("SPACE_ID", "unknown")
62
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
63
 
 
102
  return f"❌ Submission failed: {e}", pd.DataFrame(results_log)
103
 
104
  # ===========================
105
+ # Gradio Interface
106
  # ===========================
107
  with gr.Blocks() as demo:
108
  gr.Markdown("# 🎯 Hybrid GAIA Agent (65% Version)")
 
118
  # State to store HF profile
119
  user_state = gr.State()
120
 
121
+ # LoginButton profile state
122
  login_btn = gr.LoginButton()
123
  login_btn.click(lambda p: p, inputs=[login_btn], outputs=[user_state])
124