wop commited on
Commit
0a533a6
·
verified ·
1 Parent(s): 1eae31a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import json
4
+
5
+ # Load data.json
6
+ with open('data.json') as f:
7
+ data = json.load(f)
8
+
9
+ client_endpoint = "https://olivier-truong-mistral-super-fast.hf.space/chat"
10
+
11
+ def ask_question(question):
12
+ if question in data:
13
+ return data[question]
14
+ else:
15
+ response = requests.post(client_endpoint, json={"context": question})
16
+ if response.status_code == 200:
17
+ answer = response.json()['response']
18
+ data[question] = answer
19
+ with open('data.json', 'w') as f:
20
+ json.dump(data, f)
21
+ return answer
22
+ else:
23
+ return "Error: Failed to retrieve an answer."
24
+
25
+ def main():
26
+ st.title("Question Answering System")
27
+
28
+ question = st.text_input("Ask your question:")
29
+
30
+ if st.button("Ask"):
31
+ if question:
32
+ answer = ask_question(question)
33
+ st.write("Answer:", answer)
34
+ else:
35
+ st.write("Please enter a question.")
36
+
37
+ if __name__ == "__main__":
38
+ main()