Tonic commited on
Commit
3516f35
1 Parent(s): 1c1cd25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
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
- if query_data:
79
- # Extract summary and the first 5 sources
80
- summary_text = query_data["summary"]["text"]
81
- sources = query_data["responseSet"]["responseList"][:5]
82
- sources_text = [source["text"] for source in sources]
83
- return f"Summary: {summary_text}\n\nSources:\n{json.dumps(sources_text, indent=2)}"
84
- else:
85
- return "No data found in the response."
86
- else:
87
- return f"Error: {response.status_code}"
 
 
 
 
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,