frkhan commited on
Commit
4b5a0cc
·
1 Parent(s): 507f0ba

-- File downloading logic is added.

Browse files
Files changed (2) hide show
  1. app.py +31 -4
  2. langchain_agent.py +17 -16
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import gradio as gr
3
  import requests
@@ -32,6 +33,7 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
32
  api_url = DEFAULT_API_URL
33
  questions_url = f"{api_url}/questions"
34
  submit_url = f"{api_url}/submit"
 
35
 
36
  # 1. Instantiate Agent ( modify this part to create your agent)
37
  try:
@@ -71,9 +73,31 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
71
  for item in questions_data[:]:
72
  task_id = item.get("task_id")
73
  question_text = item.get("question")
 
 
74
  if not task_id or question_text is None:
75
  print(f"Skipping item with missing task_id or question: {item}")
76
  continue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  try:
78
  submitted_answer = await agent(question_text)
79
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
@@ -82,6 +106,9 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
82
  print(f"Error running agent on task {task_id}: {e}")
83
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
84
 
 
 
 
85
  if not answers_payload:
86
  print("Agent did not produce any answers to submit.")
87
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
@@ -108,7 +135,7 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
108
  results_df = pd.DataFrame(results_log)
109
  return final_status, results_df
110
  except requests.exceptions.HTTPError as e:
111
- error_detail = f"Server responded with status {e.response.status_code}."
112
  try:
113
  error_json = e.response.json()
114
  error_detail += f" Detail: {error_json.get('detail', e.response.text)}"
@@ -139,7 +166,7 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
139
  with gr.Blocks() as demo:
140
  gr.Markdown("# Basic Agent Evaluation Runner")
141
  gr.Markdown(
142
- """
143
  **Instructions:**
144
 
145
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
@@ -150,7 +177,7 @@ with gr.Blocks() as demo:
150
  **Disclaimers:**
151
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
152
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
153
- """
154
  )
155
 
156
  gr.LoginButton()
@@ -188,4 +215,4 @@ if __name__ == "__main__":
188
  print("-"*(60 + len(" App Starting ")) + "\n")
189
 
190
  print("Launching Gradio Interface for Basic Agent Evaluation...")
191
- demo.launch(debug=True, share=False, server_name="0.0.0.0")
 
1
+ import asyncio
2
  import os
3
  import gradio as gr
4
  import requests
 
33
  api_url = DEFAULT_API_URL
34
  questions_url = f"{api_url}/questions"
35
  submit_url = f"{api_url}/submit"
36
+ file_url = f"{api_url}/files"
37
 
38
  # 1. Instantiate Agent ( modify this part to create your agent)
39
  try:
 
73
  for item in questions_data[:]:
74
  task_id = item.get("task_id")
75
  question_text = item.get("question")
76
+ file_name = item.get("file_name")
77
+
78
  if not task_id or question_text is None:
79
  print(f"Skipping item with missing task_id or question: {item}")
80
  continue
81
+ if file_name:
82
+ if not os.path.exists("resource"):
83
+ os.makedirs("resource")
84
+ try:
85
+ download_url = f"{file_url}/{task_id}"
86
+ response = requests.get(download_url)
87
+ response.raise_for_status()
88
+ file_path = os.path.join("resource", file_name)
89
+ with open(file_path, "wb") as f:
90
+ f.write(response.content)
91
+ print(f"Successfully downloaded {file_name} to {file_path}")
92
+ # Read the file content and pass it to the agent
93
+ with open(file_path, "r", encoding="utf-8") as f:
94
+ file_content = f.read()
95
+ question_text = f"{question_text}\n\nFile content:\n{file_content}"
96
+ except requests.exceptions.RequestException as e:
97
+ print(f"Error downloading file {file_name}: {e}")
98
+ except IOError as e:
99
+ print(f"Error reading file {file_name}: {e}")
100
+
101
  try:
102
  submitted_answer = await agent(question_text)
103
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
 
106
  print(f"Error running agent on task {task_id}: {e}")
107
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
108
 
109
+ # Wait for a short moment to avoid overwhelming the server (optional)
110
+ await asyncio.sleep(1 * 60)
111
+
112
  if not answers_payload:
113
  print("Agent did not produce any answers to submit.")
114
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
 
135
  results_df = pd.DataFrame(results_log)
136
  return final_status, results_df
137
  except requests.exceptions.HTTPError as e:
138
+ error_detail = f"Server responded with status {e.response.status_code}. "
139
  try:
140
  error_json = e.response.json()
141
  error_detail += f" Detail: {error_json.get('detail', e.response.text)}"
 
166
  with gr.Blocks() as demo:
167
  gr.Markdown("# Basic Agent Evaluation Runner")
168
  gr.Markdown(
169
+ '''
170
  **Instructions:**
171
 
172
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
 
177
  **Disclaimers:**
178
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
179
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
180
+ '''
181
  )
182
 
183
  gr.LoginButton()
 
215
  print("-"*(60 + len(" App Starting ")) + "\n")
216
 
217
  print("Launching Gradio Interface for Basic Agent Evaluation...")
218
+ demo.launch(debug=True, share=False, server_name="0.0.0.0")
langchain_agent.py CHANGED
@@ -71,27 +71,28 @@ class LangChainAgent:
71
  tools = await client.get_tools()
72
  print(tools)
73
 
74
- # model_name = "gemini-2.0-flash"
75
- # model_provider = "google_genai" #google_genai
76
 
77
- # model = init_chat_model(model_name, model_provider=model_provider)
78
 
79
 
80
- # model_name = "deepseek-ai/deepseek-v3.1"
81
- # model_name = "deepseek-ai/deepseek-v3.1-terminus"
82
- # model_name = "minimaxai/minimax-m2"
83
- # model_name = "mistralai/mistral-nemotron"
84
- # model_name = "qwen/qwen3-next-80b-a3b-instruct"
85
- model_name = "qwen/qwen3-next-80b-a3b-thinking"
86
- # model_name = "moonshotai/kimi-k2-instruct-0905"
87
- # model_provider = "nvidia"
 
88
 
89
 
90
- model = ChatOpenAI(
91
- model=model_name,
92
- openai_api_key=os.getenv("NVIDIA_API_KEY"),
93
- openai_api_base="https://integrate.api.nvidia.com/v1"
94
- )
95
 
96
  agent = create_agent(model, tools)
97
 
 
71
  tools = await client.get_tools()
72
  print(tools)
73
 
74
+ model_name = "gemini-2.0-flash"
75
+ model_provider = "google_genai" #google_genai
76
 
77
+ model = init_chat_model(model_name, model_provider=model_provider)
78
 
79
 
80
+ # # model_name = "deepseek-ai/deepseek-v3.1"
81
+ # # model_name = "deepseek-ai/deepseek-v3.1-terminus"
82
+ # # model_name = "minimaxai/minimax-m2"
83
+ # # model_name = "mistralai/mistral-nemotron"
84
+ # # model_name = "qwen/qwen3-next-80b-a3b-instruct"
85
+ # model_name = "qwen/qwen3-next-80b-a3b-thinking"
86
+ # # model_name = "moonshotai/kimi-k2-instruct-0905"
87
+ # model_name = "nvidia/llama-3.3-nemotron-super-49b-v1.5"
88
+ # # model_provider = "nvidia"
89
 
90
 
91
+ # model = ChatOpenAI(
92
+ # model=model_name,
93
+ # openai_api_key=os.getenv("NVIDIA_API_KEY"),
94
+ # openai_api_base="https://integrate.api.nvidia.com/v1"
95
+ # )
96
 
97
  agent = create_agent(model, tools)
98