Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -73,18 +73,22 @@ def query_vectara(question):
|
|
73 |
)
|
74 |
|
75 |
|
76 |
-
if response.status_code == 200:
|
77 |
-
query_data = response.json()
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
88 |
|
89 |
iface = gr.Interface(
|
90 |
fn=query_vectara,
|
|
|
73 |
)
|
74 |
|
75 |
|
76 |
+
if response.status_code == 200:
|
77 |
+
query_data = response.json()
|
78 |
+
print(query_data)
|
79 |
+
if query_data:
|
80 |
+
# Extract summary and the first 5 sources
|
81 |
+
response_set = query_data.get('responseSet', [{}])[0] # get the first response set
|
82 |
+
summary = response_set.get('summary', [{}])[0] # get the first summary
|
83 |
+
summary_text = summary.get('text', 'No summary available')
|
84 |
+
sources = response_set.get('response', [])[:5]
|
85 |
+
sources_text = [source.get('text', '') for source in sources]
|
86 |
+
return f"Summary: {summary_text}\n\nSources:\n{json.dumps(sources_text, indent=2)}"
|
87 |
+
else:
|
88 |
+
return "No data found in the response."
|
89 |
+
else:
|
90 |
+
return f"Error: {response.status_code}"
|
91 |
+
|
92 |
|
93 |
iface = gr.Interface(
|
94 |
fn=query_vectara,
|