Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,22 @@ 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
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
except requests.exceptions.RequestException as e:
|
| 14 |
return {"error": str(e)}
|
| 15 |
|
|
@@ -30,11 +40,19 @@ def main():
|
|
| 30 |
"question": user_input,
|
| 31 |
})
|
| 32 |
|
| 33 |
-
# Display the
|
| 34 |
-
st.subheader("
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
| 37 |
st.warning("Please enter a question before submitting.")
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
| 40 |
-
main()
|
|
|
|
| 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 toolOutput
|
| 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 |
+
# Return the full response and toolOutput
|
| 22 |
+
return {"raw_response": data, "tool_output": tool_outputs}
|
| 23 |
except requests.exceptions.RequestException as e:
|
| 24 |
return {"error": str(e)}
|
| 25 |
|
|
|
|
| 40 |
"question": user_input,
|
| 41 |
})
|
| 42 |
|
| 43 |
+
# Display the extracted toolOutput on the main page
|
| 44 |
+
st.subheader("Extracted Tool Output:")
|
| 45 |
+
tool_output = response.get("tool_output", [])
|
| 46 |
+
if tool_output:
|
| 47 |
+
st.write(tool_output)
|
| 48 |
+
else:
|
| 49 |
+
st.write("No toolOutput data found in the response.")
|
| 50 |
+
|
| 51 |
+
# Display the raw JSON response in the sidebar
|
| 52 |
+
st.sidebar.header("Raw JSON Response")
|
| 53 |
+
st.sidebar.json(response.get("raw_response", {}))
|
| 54 |
else:
|
| 55 |
st.warning("Please enter a question before submitting.")
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
+
main()
|