Spaces:
Runtime error
Runtime error
aaravlovescodes
commited on
Commit
•
1ebd87c
1
Parent(s):
aaa6c56
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,25 @@
|
|
1 |
import time
|
2 |
import streamlit as st
|
3 |
import requests
|
4 |
-
headers = {"Authorization": "Bearer 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"}
|
5 |
|
|
|
6 |
|
7 |
-
st.title("
|
8 |
-
option = st.selectbox(
|
9 |
-
|
10 |
-
|
11 |
-
elif option == 'roberta-base-squad2-distilled':
|
12 |
-
API_URL = 'https://api-inference.huggingface.co/models/deepset/roberta-base-squad2-distilled'
|
13 |
-
elif option == 'xlm-roberta-large-squad2':
|
14 |
-
API_URL = "https://api-inference.huggingface.co/models/deepset/xlm-roberta-large-squad2"
|
15 |
-
if option == 'bert-large-cased-whole-word-masking-finetuned-squad':
|
16 |
-
API_URL = 'https://api-inference.huggingface.co/models/bert-large-cased-whole-word-masking-finetuned-squad'
|
17 |
-
st.write(API_URL)
|
18 |
text_input = st.text_area("Enter some context👇")
|
19 |
text_question = st.text_input("Enter a question regarding that context👇")
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def query(payload):
|
23 |
retries = 0
|
24 |
while True:
|
@@ -31,10 +32,13 @@ def query(payload):
|
|
31 |
print(f"Too many requests. Retrying in {wait_time} seconds...")
|
32 |
time.sleep(wait_time)
|
33 |
else:
|
34 |
-
|
35 |
return None
|
36 |
|
37 |
|
38 |
if st.button("Send"):
|
39 |
output = query({"inputs": {"question": text_question, "context": text_input}})
|
40 |
-
|
|
|
|
|
|
|
|
1 |
import time
|
2 |
import streamlit as st
|
3 |
import requests
|
|
|
4 |
|
5 |
+
headers = {"Authorization": "Bearer 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"}
|
6 |
|
7 |
+
st.title("extractive-qa")
|
8 |
+
option = st.selectbox(
|
9 |
+
'Select a model👇',
|
10 |
+
('distilbert-base-cased-distilled-squad', 'roberta-base-squad2-distilled', 'xlm-roberta-large-squad2', 'bert-large-cased-whole-word-masking-finetuned-squad'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
text_input = st.text_area("Enter some context👇")
|
12 |
text_question = st.text_input("Enter a question regarding that context👇")
|
13 |
|
14 |
+
if option == 'distilbert-base-cased-distilled-squad':
|
15 |
+
API_URL = "https://api-inference.huggingface.co/models/distilbert-base-cased-distilled-squad"
|
16 |
+
elif option == "roberta-base-squad2-distilled":
|
17 |
+
API_URL="https://api-inference.huggingface.co/models/deepset/roberta-base-squad2-distilled"
|
18 |
+
elif option == 'xlm-roberta-large-squad2':
|
19 |
+
API_URL="https://api-inference.huggingface.co/models/deepset/xlm-roberta-large-squad2"
|
20 |
+
if option == "bert-large-cased-whole-word-masking-finetuned-squad":
|
21 |
+
API_URL = "https://api-inference.huggingface.co/models/bert-large-cased-whole-word-masking-finetuned-squad"
|
22 |
+
|
23 |
def query(payload):
|
24 |
retries = 0
|
25 |
while True:
|
|
|
32 |
print(f"Too many requests. Retrying in {wait_time} seconds...")
|
33 |
time.sleep(wait_time)
|
34 |
else:
|
35 |
+
st.error(f"Request failed with status code {response.status_code}. Try Again!", icon="🚨")
|
36 |
return None
|
37 |
|
38 |
|
39 |
if st.button("Send"):
|
40 |
output = query({"inputs": {"question": text_question, "context": text_input}})
|
41 |
+
if output:
|
42 |
+
answer = output["answer"]
|
43 |
+
st.write(output)
|
44 |
+
|