Spaces:
Sleeping
Sleeping
Update pages/1_Turkish_QA_for_SQuAD.py
Browse files- pages/1_Turkish_QA_for_SQuAD.py +76 -74
pages/1_Turkish_QA_for_SQuAD.py
CHANGED
@@ -1,74 +1,76 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
-
st.set_page_config(page_title="Turkish Question-Answering - via AG", page_icon='📖')
|
4 |
-
st.header("📖Turkish QA Task for SQuAD - TR")
|
5 |
-
|
6 |
-
with st.sidebar:
|
7 |
-
hf_key = st.text_input("HuggingFace Access Key", key="hf_key", type="password")
|
8 |
-
|
9 |
-
MODEL_QA = {
|
10 |
-
"mdeberta": "anilguven/mdeberta_tr_qa_turkish_squad",
|
11 |
-
"albert": "anilguven/albert_tr_qa_turkish_squad",
|
12 |
-
"distilbert": "anilguven/distilbert_tr_qa_turkish_squad",
|
13 |
-
"bert": "anilguven/bert_tr_qa_turkish_squad",
|
14 |
-
}
|
15 |
-
|
16 |
-
MODEL_QAS = ["mdeberta","albert","distilbert","bert"]
|
17 |
-
|
18 |
-
# Use a pipeline as a high-level helper
|
19 |
-
from transformers import pipeline
|
20 |
-
# Create a mapping from formatted model names to their original identifiers
|
21 |
-
def format_model_name(model_key):
|
22 |
-
name_parts = model_key
|
23 |
-
formatted_name = ''.join(name_parts) # Join them into a single string with title case
|
24 |
-
return formatted_name
|
25 |
-
|
26 |
-
formatted_names_to_identifiers = {
|
27 |
-
format_model_name(key): key for key in MODEL_QA.keys()
|
28 |
-
}
|
29 |
-
|
30 |
-
# Debug to ensure names are formatted correctly
|
31 |
-
#st.write("Formatted Model Names to Identifiers:", formatted_names_to_identifiers
|
32 |
-
|
33 |
-
with st.expander("About this app"):
|
34 |
-
st.write(f"""
|
35 |
-
1-Choose your model for Turkish Question-answering task for SQuAD-tr dataset.\n
|
36 |
-
2-Enter your context-question pair.\n
|
37 |
-
3-And model predict your response.
|
38 |
-
""")
|
39 |
-
|
40 |
-
model_name: str = st.selectbox("Model", options=MODEL_QAS)
|
41 |
-
selected_model = MODEL_QA[model_name]
|
42 |
-
|
43 |
-
if not hf_key:
|
44 |
-
st.info("Please add your HuggingFace Access Key to continue.")
|
45 |
-
st.stop()
|
46 |
-
|
47 |
-
access_token = hf_key
|
48 |
-
pipe = pipeline("question-answering", model=selected_model, token=access_token)
|
49 |
-
|
50 |
-
#from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
51 |
-
#tokenizer = AutoTokenizer.from_pretrained(selected_model)
|
52 |
-
#pipe = AutoModelForSequenceClassification.from_pretrained(pretrained_model_name_or_path=selected_model)
|
53 |
-
|
54 |
-
# Display the selected model using the formatted name
|
55 |
-
model_display_name = selected_model # Already formatted
|
56 |
-
st.write(f"Model being used: `{model_display_name}`")
|
57 |
-
|
58 |
-
with st.form('my_form'):
|
59 |
-
context = st.text_area('Enter text:', "Normanlar (Normans: Nourmands; Fransizca: Normands; Latince: Normanni), 10. ve 11. yüzyillarda Fransa'da bir bölge olan Normandiya'ya adini veren insanlardir. Onlar Iskandinav soyundan ('Norman' 'Norseman' geliyor) akincilari ve Danimarka, Izlanda ve Norveç'ten korsanlar, liderleri Rollo altinda, Bati Francia Krali Charles III sadakat yemini etmeyi kabul etti. Nesiller boyunca asimilasyon ve yerli Frenk ve Roman-Galya nüfuslariyla karistirma, torunlari yavas yavas Bati Francia'nin Karolina kökenli kültürleriyle birlesecekti. Normanlarin farkli kültürel ve etnik kimligi baslangiçta 10. yüzyilin ilk yarisinda ortaya çikti ve devam eden yüzyillar boyunca gelismeye devam etti.")
|
60 |
-
question = st.text_input("Enter your question for analysis:", "Normandiya hangi ülkede bulunur?")
|
61 |
-
submitted = st.form_submit_button('Submit')
|
62 |
-
|
63 |
-
if submitted:
|
64 |
-
if not hf_key:
|
65 |
-
st.info("Please add your HuggingFace Access Key to continue.")
|
66 |
-
st.stop()
|
67 |
-
|
68 |
-
else:
|
69 |
-
result = pipe(question=question, context=context)
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(page_title="Turkish Question-Answering - via AG", page_icon='📖')
|
4 |
+
st.header("📖Turkish QA Task for SQuAD - TR")
|
5 |
+
|
6 |
+
with st.sidebar:
|
7 |
+
hf_key = st.text_input("HuggingFace Access Key", key="hf_key", type="password")
|
8 |
+
|
9 |
+
MODEL_QA = {
|
10 |
+
"mdeberta": "anilguven/mdeberta_tr_qa_turkish_squad",
|
11 |
+
"albert": "anilguven/albert_tr_qa_turkish_squad",
|
12 |
+
"distilbert": "anilguven/distilbert_tr_qa_turkish_squad",
|
13 |
+
"bert": "anilguven/bert_tr_qa_turkish_squad",
|
14 |
+
}
|
15 |
+
|
16 |
+
MODEL_QAS = ["mdeberta","albert","distilbert","bert"]
|
17 |
+
|
18 |
+
# Use a pipeline as a high-level helper
|
19 |
+
from transformers import pipeline
|
20 |
+
# Create a mapping from formatted model names to their original identifiers
|
21 |
+
def format_model_name(model_key):
|
22 |
+
name_parts = model_key
|
23 |
+
formatted_name = ''.join(name_parts) # Join them into a single string with title case
|
24 |
+
return formatted_name
|
25 |
+
|
26 |
+
formatted_names_to_identifiers = {
|
27 |
+
format_model_name(key): key for key in MODEL_QA.keys()
|
28 |
+
}
|
29 |
+
|
30 |
+
# Debug to ensure names are formatted correctly
|
31 |
+
#st.write("Formatted Model Names to Identifiers:", formatted_names_to_identifiers
|
32 |
+
|
33 |
+
with st.expander("About this app"):
|
34 |
+
st.write(f"""
|
35 |
+
1-Choose your model for Turkish Question-answering task for SQuAD-tr dataset.\n
|
36 |
+
2-Enter your context-question pair.\n
|
37 |
+
3-And model predict your response.
|
38 |
+
""")
|
39 |
+
|
40 |
+
model_name: str = st.selectbox("Model", options=MODEL_QAS)
|
41 |
+
selected_model = MODEL_QA[model_name]
|
42 |
+
|
43 |
+
if not hf_key:
|
44 |
+
st.info("Please add your HuggingFace Access Key to continue.")
|
45 |
+
st.stop()
|
46 |
+
|
47 |
+
access_token = hf_key
|
48 |
+
pipe = pipeline("question-answering", model=selected_model, token=access_token)
|
49 |
+
|
50 |
+
#from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
51 |
+
#tokenizer = AutoTokenizer.from_pretrained(selected_model)
|
52 |
+
#pipe = AutoModelForSequenceClassification.from_pretrained(pretrained_model_name_or_path=selected_model)
|
53 |
+
|
54 |
+
# Display the selected model using the formatted name
|
55 |
+
model_display_name = selected_model # Already formatted
|
56 |
+
st.write(f"Model being used: `{model_display_name}`")
|
57 |
+
|
58 |
+
with st.form('my_form'):
|
59 |
+
context = st.text_area('Enter text:', "Normanlar (Normans: Nourmands; Fransizca: Normands; Latince: Normanni), 10. ve 11. yüzyillarda Fransa'da bir bölge olan Normandiya'ya adini veren insanlardir. Onlar Iskandinav soyundan ('Norman' 'Norseman' geliyor) akincilari ve Danimarka, Izlanda ve Norveç'ten korsanlar, liderleri Rollo altinda, Bati Francia Krali Charles III sadakat yemini etmeyi kabul etti. Nesiller boyunca asimilasyon ve yerli Frenk ve Roman-Galya nüfuslariyla karistirma, torunlari yavas yavas Bati Francia'nin Karolina kökenli kültürleriyle birlesecekti. Normanlarin farkli kültürel ve etnik kimligi baslangiçta 10. yüzyilin ilk yarisinda ortaya çikti ve devam eden yüzyillar boyunca gelismeye devam etti.")
|
60 |
+
question = st.text_input("Enter your question for analysis:", "Normandiya hangi ülkede bulunur?")
|
61 |
+
submitted = st.form_submit_button('Submit')
|
62 |
+
|
63 |
+
if submitted:
|
64 |
+
if not hf_key:
|
65 |
+
st.info("Please add your HuggingFace Access Key to continue.")
|
66 |
+
st.stop()
|
67 |
+
|
68 |
+
else:
|
69 |
+
result = pipe(question=question, context=context)
|
70 |
+
if result["score"] < 0.40:
|
71 |
+
result["answer"] = "Cevap bulunamadı"
|
72 |
+
st.text("Your response: \n " + str(result["answer"]) + "\n" + str(result["score"]*100)[:5] + " with score")
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
|