danielkorat commited on
Commit
280784e
·
verified ·
1 Parent(s): 44fad3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -49,11 +49,11 @@ from smolagents.gradio_ui import pull_messages_from_step, handle_agent_output_ty
49
 
50
  # login(os.getenv("HF_TOKEN"))
51
 
52
- WOLFRAM_RESPONSE_KEYS = [
53
- "Result",
54
- "Solution",
55
- "RealSolution",
56
- ]
57
 
58
  image_generation_tool = load_tool("danielkorat/text-to-image", trust_remote_code=True)
59
 
@@ -71,8 +71,6 @@ def wolfram_alpha(query: str)-> str:
71
  api_key = os.environ["WOLFRAM_ALPHA_APPID"]
72
  formatted_query = parse.quote_plus(query)
73
  url = f"http://api.wolframalpha.com/v2/query?appid={api_key}&input={formatted_query}&output=json&format=plaintext"
74
- for key in WOLFRAM_RESPONSE_KEYS:
75
- url += f"&includepodid={key}"
76
 
77
  try:
78
  response = requests.get(url)
@@ -87,8 +85,19 @@ def wolfram_alpha(query: str)-> str:
87
  if (pods := query_result.get("pods")) is None: # Check if the response is missing an answer
88
  return "Wolfram did not provide an answer (no result pods)."
89
 
90
- return "; ".join(res.get("plaintext") for res in pods[0].get("subpods"))
91
-
 
 
 
 
 
 
 
 
 
 
 
92
  except requests.exceptions.RequestException as e:
93
  print(requests.exceptions.RequestException, e)
94
 
 
49
 
50
  # login(os.getenv("HF_TOKEN"))
51
 
52
+ # WOLFRAM_RESPONSE_KEYS = [
53
+ # "Result",
54
+ # "Solution",
55
+ # "RealSolution",
56
+ # ]
57
 
58
  image_generation_tool = load_tool("danielkorat/text-to-image", trust_remote_code=True)
59
 
 
71
  api_key = os.environ["WOLFRAM_ALPHA_APPID"]
72
  formatted_query = parse.quote_plus(query)
73
  url = f"http://api.wolframalpha.com/v2/query?appid={api_key}&input={formatted_query}&output=json&format=plaintext"
 
 
74
 
75
  try:
76
  response = requests.get(url)
 
85
  if (pods := query_result.get("pods")) is None: # Check if the response is missing an answer
86
  return "Wolfram did not provide an answer (no result pods)."
87
 
88
+ res = ""
89
+ for pod in pods:
90
+ res += f"{pod['title']}: "
91
+ for subpod in pod.get("subpods"):
92
+ sub_title = subpod.get('title')
93
+ if sub_title is not None and sub_title != "":
94
+ sub_title += ": "
95
+ res += f"{sub_title}{subpod.get('plaintext', 'N/A')}; "
96
+ res += "\n"
97
+
98
+ print(f"{queryres=}")
99
+ return res
100
+
101
  except requests.exceptions.RequestException as e:
102
  print(requests.exceptions.RequestException, e)
103