ositamiles commited on
Commit
35e684c
·
verified ·
1 Parent(s): 7154687

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -4,28 +4,29 @@ import requests
4
  # API URL
5
  API_URL = "https://startrz-devi.hf.space/api/v1/prediction/e54adffc-ae77-42e5-9fc0-c4584e081093"
6
 
7
- # Function to query the API and extract information
8
  def query(payload):
9
  try:
10
  response = requests.post(API_URL, json=payload)
11
  response.raise_for_status() # Raise an error for bad HTTP responses
12
  data = response.json() # Parse the JSON response
13
 
14
- # Extract toolOutput if present
15
  tool_outputs = []
16
  if "agentReasoning" in data:
17
  for reasoning in data["agentReasoning"]:
18
  if "usedTools" in reasoning:
19
  tool_outputs.extend(reasoning["usedTools"])
20
 
21
- # Extract title and content from "text"
22
- title, content = None, None
 
23
  if "text" in data:
24
  text_data = data["text"]
25
- title = text_data.get("title", "No title available")
26
- content = text_data.get("content", "No content available")
27
 
28
- # Return all extracted data
29
  return {
30
  "raw_response": data,
31
  "tool_output": tool_outputs,
@@ -52,7 +53,7 @@ def main():
52
  "question": user_input,
53
  })
54
 
55
- # Display the extracted toolOutput
56
  st.subheader("Extracted Tool Output:")
57
  tool_output = response.get("tool_output", [])
58
  if tool_output:
@@ -60,14 +61,20 @@ def main():
60
  else:
61
  st.write("No toolOutput data found in the response.")
62
 
63
- # Display the extracted title and content
64
  st.subheader("Title:")
65
- title = response.get("title", "No title available")
66
- st.write(title)
 
 
 
67
 
68
  st.subheader("Content:")
69
- content = response.get("content", "No content available")
70
- st.write(content)
 
 
 
71
 
72
  # Display the raw JSON response in the sidebar
73
  st.sidebar.header("Raw JSON Response")
 
4
  # API URL
5
  API_URL = "https://startrz-devi.hf.space/api/v1/prediction/e54adffc-ae77-42e5-9fc0-c4584e081093"
6
 
7
+ # Function to query the API and extract required fields
8
  def query(payload):
9
  try:
10
  response = requests.post(API_URL, json=payload)
11
  response.raise_for_status() # Raise an error for bad HTTP responses
12
  data = response.json() # Parse the JSON response
13
 
14
+ # Extract toolOutput if present in the response
15
  tool_outputs = []
16
  if "agentReasoning" in data:
17
  for reasoning in data["agentReasoning"]:
18
  if "usedTools" in reasoning:
19
  tool_outputs.extend(reasoning["usedTools"])
20
 
21
+ # Extract title and content from "text" field
22
+ title = None
23
+ content = None
24
  if "text" in data:
25
  text_data = data["text"]
26
+ title = text_data.get("title")
27
+ content = text_data.get("content")
28
 
29
+ # Return the full response, toolOutput, title, and content
30
  return {
31
  "raw_response": data,
32
  "tool_output": tool_outputs,
 
53
  "question": user_input,
54
  })
55
 
56
+ # Display the extracted toolOutput on the main page
57
  st.subheader("Extracted Tool Output:")
58
  tool_output = response.get("tool_output", [])
59
  if tool_output:
 
61
  else:
62
  st.write("No toolOutput data found in the response.")
63
 
64
+ # Display the extracted title and content on the main page
65
  st.subheader("Title:")
66
+ title = response.get("title")
67
+ if title:
68
+ st.write(title)
69
+ else:
70
+ st.write("No title found in the response.")
71
 
72
  st.subheader("Content:")
73
+ content = response.get("content")
74
+ if content:
75
+ st.write(content)
76
+ else:
77
+ st.write("No content found in the response.")
78
 
79
  # Display the raw JSON response in the sidebar
80
  st.sidebar.header("Raw JSON Response")