Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
# Load data.json
|
| 6 |
with open('data.json') as f:
|
|
@@ -22,6 +23,12 @@ def ask_question(question):
|
|
| 22 |
else:
|
| 23 |
return "Error: Failed to retrieve an answer."
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def main():
|
| 26 |
st.title("Question Answering System")
|
| 27 |
|
|
@@ -29,8 +36,11 @@ def main():
|
|
| 29 |
|
| 30 |
if st.button("Ask"):
|
| 31 |
if question:
|
|
|
|
|
|
|
| 32 |
answer = ask_question(question)
|
| 33 |
-
|
|
|
|
| 34 |
else:
|
| 35 |
st.write("Please enter a question.")
|
| 36 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
# Load data.json
|
| 7 |
with open('data.json') as f:
|
|
|
|
| 23 |
else:
|
| 24 |
return "Error: Failed to retrieve an answer."
|
| 25 |
|
| 26 |
+
def animate_typing(text):
|
| 27 |
+
for char in text:
|
| 28 |
+
st.write(char, end='', flush=True)
|
| 29 |
+
time.sleep(0.05)
|
| 30 |
+
st.write("")
|
| 31 |
+
|
| 32 |
def main():
|
| 33 |
st.title("Question Answering System")
|
| 34 |
|
|
|
|
| 36 |
|
| 37 |
if st.button("Ask"):
|
| 38 |
if question:
|
| 39 |
+
answer_placeholder = st.empty()
|
| 40 |
+
answer_placeholder.write("Thinking...")
|
| 41 |
answer = ask_question(question)
|
| 42 |
+
answer_placeholder.empty()
|
| 43 |
+
animate_typing("Answer: " + answer)
|
| 44 |
else:
|
| 45 |
st.write("Please enter a question.")
|
| 46 |
|