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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -63,9 +63,11 @@ class HybridAgent65:
63
  # ===========================
64
  # Run & Submit
65
  # ===========================
66
- def run_and_submit_all(profile):
67
- if profile is None:
 
68
  return "❌ Please login with your Hugging Face account.", None
 
69
  username = profile["username"] if isinstance(profile, dict) else profile.username
70
  space_id = os.getenv("SPACE_ID", "unknown")
71
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
@@ -111,7 +113,7 @@ def run_and_submit_all(profile):
111
  return f"❌ Submission failed: {e}", pd.DataFrame(results_log)
112
 
113
  # ===========================
114
- # Gradio Interface (compatible with latest HF login)
115
  # ===========================
116
  with gr.Blocks() as demo:
117
  gr.Markdown("# 🎯 Hybrid GAIA Agent (65% Version)")
@@ -124,13 +126,18 @@ with gr.Blocks() as demo:
124
  """
125
  )
126
 
 
 
 
 
127
  login_btn = gr.LoginButton()
 
 
128
  run_button = gr.Button("🚀 Run Evaluation & Submit All Answers")
129
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
130
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
131
 
132
- # HF login returns profile dict,直接作為 run 函數輸入
133
- run_button.click(fn=run_and_submit_all, inputs=[login_btn], outputs=[status_output, results_table])
134
 
135
  if __name__ == "__main__":
136
  demo.launch(debug=True, share=False)
 
63
  # ===========================
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"
 
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)")
 
126
  """
127
  )
128
 
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
+
136
  run_button = gr.Button("🚀 Run Evaluation & Submit All Answers")
137
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
138
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
139
 
140
+ run_button.click(fn=run_and_submit_all, inputs=[user_state], outputs=[status_output, results_table])
 
141
 
142
  if __name__ == "__main__":
143
  demo.launch(debug=True, share=False)