Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,25 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
from gradio_client import Client
|
| 4 |
import time
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
client_endpoint = "https://olivier-truong-mistral-super-fast.hf.space/"
|
| 11 |
|
| 12 |
def ask_question(question):
|
| 13 |
-
if question in
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
else:
|
| 16 |
client = Client(client_endpoint)
|
| 17 |
result = client.predict(
|
|
@@ -24,9 +32,11 @@ def ask_question(question):
|
|
| 24 |
)
|
| 25 |
answer = result
|
| 26 |
answer = answer[:-4]
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
return answer
|
| 31 |
|
| 32 |
def typewriter(text: str, speed: int):
|
|
@@ -39,7 +49,7 @@ def typewriter(text: str, speed: int):
|
|
| 39 |
|
| 40 |
def main():
|
| 41 |
st.title("Near Instant Question Answering")
|
| 42 |
-
st.write("Limitations: May generate
|
| 43 |
|
| 44 |
question = st.text_input("Ask your question:")
|
| 45 |
|
|
@@ -55,3 +65,4 @@ def main():
|
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
main()
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from pymongo import MongoClient
|
| 3 |
from gradio_client import Client
|
| 4 |
import time
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
# Connect to MongoDB
|
| 8 |
+
password = os.getenv("password")
|
| 9 |
+
uri = f"mongodb+srv://E:{password}@cluster0.rvt8psd.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
|
| 10 |
+
client = MongoClient(uri)
|
| 11 |
+
db = client["instantqa"]
|
| 12 |
+
collection = db["instantqa"]
|
| 13 |
|
| 14 |
client_endpoint = "https://olivier-truong-mistral-super-fast.hf.space/"
|
| 15 |
|
| 16 |
def ask_question(question):
|
| 17 |
+
# Check if the question exists in the database
|
| 18 |
+
query = {"question": question}
|
| 19 |
+
result = collection.find_one(query)
|
| 20 |
+
|
| 21 |
+
if result:
|
| 22 |
+
return result["answer"]
|
| 23 |
else:
|
| 24 |
client = Client(client_endpoint)
|
| 25 |
result = client.predict(
|
|
|
|
| 32 |
)
|
| 33 |
answer = result
|
| 34 |
answer = answer[:-4]
|
| 35 |
+
|
| 36 |
+
# Store the question-answer pair in MongoDB
|
| 37 |
+
data = {"question": question, "answer": answer}
|
| 38 |
+
collection.insert_one(data)
|
| 39 |
+
|
| 40 |
return answer
|
| 41 |
|
| 42 |
def typewriter(text: str, speed: int):
|
|
|
|
| 49 |
|
| 50 |
def main():
|
| 51 |
st.title("Near Instant Question Answering")
|
| 52 |
+
st.write("Limitations: May generate unhelpful or outdated content, no chat history.")
|
| 53 |
|
| 54 |
question = st.text_input("Ask your question:")
|
| 55 |
|
|
|
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
main()
|
| 68 |
+
|