medmiu commited on
Commit
d72b062
·
verified ·
1 Parent(s): f84dff3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -25
app.py CHANGED
@@ -18,7 +18,7 @@ import gradio as gr
18
  import requests
19
  import json
20
 
21
- OR_API_KEY = "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"
22
  HEADERS = {
23
  "Authorization": f"Bearer {OR_API_KEY}",
24
  "Content-Type": "application/json",
@@ -26,36 +26,15 @@ HEADERS = {
26
  "X-Title": "<YOUR_SITE_NAME>", # Optional. Site title for rankings on openrouter.ai.
27
  }
28
 
29
- def get_concise_answer(prompt):
30
- response = requests.post(
31
- url="https://openrouter.ai/api/v1/chat/completions",
32
- headers=HEADERS,
33
- data=json.dumps({
34
- "model": "deepseek/deepseek-chat-v3-0324:free",
35
- "messages": [
36
- {
37
- "role": "system",
38
- "content": "you are a helpful assistant that gives concise response. For example you don't add prefixes or the reflection to the answer message. For instance if the user asks you how many albums and the response is 3 just type 3 only"
39
- },
40
- {
41
- "role": "user",
42
- "content": prompt
43
- }
44
- ],
45
- })
46
- )
47
-
48
- data = response.json()
49
- model_response = data['choices'][0]['message']['content']
50
- return model_response
51
 
 
52
  # Example usage:
53
  prompt1 = "Hello, what is the cultural capital of morocco?"
54
  print(get_concise_answer(prompt1))
55
 
56
  prompt2 = "how many albums does maher zain have?"
57
  print(get_concise_answer(prompt2))
58
-
59
 
60
 
61
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -183,6 +162,29 @@ agent = workflow.compile()
183
 
184
  # 6. Run Function
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  def run_groq_agent(query: str):
187
  response = agent.invoke({
188
  "messages": [HumanMessage(content=query)],
@@ -261,7 +263,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
261
  print(f"Skipping item with missing task_id or question: {item}")
262
  continue
263
  try:
264
- submitted_answer = run_groq_agent(question_text)
 
265
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
266
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
267
  except Exception as e:
 
18
  import requests
19
  import json
20
 
21
+ OR_API_KEY = os.getenv("OR_API_KEY")
22
  HEADERS = {
23
  "Authorization": f"Bearer {OR_API_KEY}",
24
  "Content-Type": "application/json",
 
26
  "X-Title": "<YOUR_SITE_NAME>", # Optional. Site title for rankings on openrouter.ai.
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ '''
31
  # Example usage:
32
  prompt1 = "Hello, what is the cultural capital of morocco?"
33
  print(get_concise_answer(prompt1))
34
 
35
  prompt2 = "how many albums does maher zain have?"
36
  print(get_concise_answer(prompt2))
37
+ '''
38
 
39
 
40
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
162
 
163
  # 6. Run Function
164
 
165
+ def get_concise_answer(prompt):
166
+ response = requests.post(
167
+ url="https://openrouter.ai/api/v1/chat/completions",
168
+ headers=HEADERS,
169
+ data=json.dumps({
170
+ "model": "deepseek/deepseek-chat-v3-0324:free",
171
+ "messages": [
172
+ {
173
+ "role": "system",
174
+ "content": "you are a helpful assistant that gives concise response. For example you don't add prefixes or the reflection to the answer message. For instance if the user asks you how many albums and the response is 3 just type 3 only"
175
+ },
176
+ {
177
+ "role": "user",
178
+ "content": prompt
179
+ }
180
+ ],
181
+ })
182
+ )
183
+
184
+ data = response.json()
185
+ model_response = data['choices'][0]['message']['content']
186
+ return model_response
187
+
188
  def run_groq_agent(query: str):
189
  response = agent.invoke({
190
  "messages": [HumanMessage(content=query)],
 
263
  print(f"Skipping item with missing task_id or question: {item}")
264
  continue
265
  try:
266
+ submitted_answer = get_concise_answer(question_text)
267
+ #submitted_answer = run_groq_agent(question_text)
268
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
269
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
270
  except Exception as e: