Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import traceback
|
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
import asyncio
|
|
|
|
| 6 |
from haystack_integrations.document_stores.mongodb_atlas import MongoDBAtlasDocumentStore
|
| 7 |
from haystack import Pipeline, Document
|
| 8 |
from haystack.components.generators import OpenAIGenerator
|
|
@@ -87,9 +88,9 @@ try:
|
|
| 87 |
rag_pipeline.connect("retriever", "prompt_builder.documents")
|
| 88 |
rag_pipeline.connect("prompt_builder", "llm")
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
|
| 95 |
def get_movies(message, history):
|
|
@@ -114,7 +115,15 @@ def get_movies(message, history):
|
|
| 114 |
|
| 115 |
# Convert documents to a format suitable for Gradio Dataframe
|
| 116 |
data_for_dataframe = [[doc.content] for doc in documents]
|
| 117 |
-
headers = ["Plot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
def update_movie_data(new_data):
|
| 120 |
"""
|
|
@@ -134,15 +143,18 @@ def update_movie_data(new_data):
|
|
| 134 |
return new_data
|
| 135 |
# Setup Gradio interface
|
| 136 |
with gr.Blocks() as demo:
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
| 147 |
if __name__ == "__main__":
|
| 148 |
demo.launch()
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
import asyncio
|
| 6 |
+
import requests
|
| 7 |
from haystack_integrations.document_stores.mongodb_atlas import MongoDBAtlasDocumentStore
|
| 8 |
from haystack import Pipeline, Document
|
| 9 |
from haystack.components.generators import OpenAIGenerator
|
|
|
|
| 88 |
rag_pipeline.connect("retriever", "prompt_builder.documents")
|
| 89 |
rag_pipeline.connect("prompt_builder", "llm")
|
| 90 |
|
| 91 |
+
# Exception handling to catch and display errors during the pipeline execution.
|
| 92 |
+
except Exception as e:
|
| 93 |
+
print("An error occurred: \n" + error_message)
|
| 94 |
|
| 95 |
|
| 96 |
def get_movies(message, history):
|
|
|
|
| 115 |
|
| 116 |
# Convert documents to a format suitable for Gradio Dataframe
|
| 117 |
data_for_dataframe = [[doc.content] for doc in documents]
|
| 118 |
+
headers = ["Plot
|
| 119 |
+
|
| 120 |
+
def fetch_url_data(url):
|
| 121 |
+
try:
|
| 122 |
+
response = requests.get(url)
|
| 123 |
+
response.raise_for_status() # Raises an HTTPError if the HTTP request returned an unsuccessful status code
|
| 124 |
+
return response.text
|
| 125 |
+
except requests.RequestException as e:
|
| 126 |
+
return f"Error: {e}"
|
| 127 |
|
| 128 |
def update_movie_data(new_data):
|
| 129 |
"""
|
|
|
|
| 143 |
return new_data
|
| 144 |
# Setup Gradio interface
|
| 145 |
with gr.Blocks() as demo:
|
| 146 |
+
with gr.Tab("Chat"):
|
| 147 |
+
gr.Markdown("## Movie Plot Viewer")
|
| 148 |
+
movie_table = gr.Dataframe(value=data_for_dataframe, headers=headers, interactive=False)
|
| 149 |
+
submit_button = gr.Button("Update Data")
|
| 150 |
+
## value=[(None, "Hi, I'm a MongoDB and Heystack based question and answer bot 🤖, I can help you answer on the knowledge base above…")]
|
| 151 |
+
gr.ChatInterface(get_movies,examples=["What characters are from Rome?", "Combine 3 plots of your choice", "List all characters"], title="Atlas Vector Search Chat",description="This small chat uses a similarity search to find relevant plots as listed above, it uses MongoDB Atlas and Haystack integaration: https://haystack.deepset.ai/integrations/mongodb",submit_btn="Search").queue()
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
submit_button.click(fn=update_movie_data, inputs=[movie_table], outputs=[movie_table])
|
| 156 |
+
with gr.Tab("Code"):
|
| 157 |
+
gr.Code(label="Code", language="python", value=fetch_url_data('https://huggingface.co/spaces/MongoDB/Haystack-MongoDB-Integration-Chat/raw/main/app.py'))
|
| 158 |
+
|
| 159 |
if __name__ == "__main__":
|
| 160 |
demo.launch()
|