Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from decouple import Config
|
|
5 |
|
6 |
config = Config('.env')
|
7 |
|
|
|
8 |
def query_vectara(question):
|
9 |
user_message = question
|
10 |
|
@@ -90,6 +91,23 @@ def query_vectara(question):
|
|
90 |
return f"Error: {response.status_code}"
|
91 |
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
iface = gr.Interface(
|
94 |
fn=query_vectara,
|
95 |
inputs=[gr.Textbox(label="Input Text")],
|
|
|
5 |
|
6 |
config = Config('.env')
|
7 |
|
8 |
+
|
9 |
def query_vectara(question):
|
10 |
user_message = question
|
11 |
|
|
|
91 |
return f"Error: {response.status_code}"
|
92 |
|
93 |
|
94 |
+
def convert_to_markdown(vectara_response):
|
95 |
+
if vectara_response:
|
96 |
+
# Extract summary and the first 5 sources
|
97 |
+
response_set = vectara_response.get('responseSet', [{}])[0] # get the first response set
|
98 |
+
summary = response_set.get('summary', [{}])[0] # get the first summary
|
99 |
+
summary_text = summary.get('text', 'No summary available')
|
100 |
+
sources = response_set.get('response', [])[:5]
|
101 |
+
sources_text = [source.get('text', '') for source in sources]
|
102 |
+
|
103 |
+
# Format the summary and sources as Markdown
|
104 |
+
markdown_summary = f"**Summary**: {summary_text}\n\n"
|
105 |
+
markdown_sources = "\n".join([f"- {source}" for source in sources_text])
|
106 |
+
|
107 |
+
return f"{markdown_summary}**Sources**:\n{markdown_sources}"
|
108 |
+
else:
|
109 |
+
return "No data found in the response."
|
110 |
+
|
111 |
iface = gr.Interface(
|
112 |
fn=query_vectara,
|
113 |
inputs=[gr.Textbox(label="Input Text")],
|