Spaces:
Sleeping
Sleeping
huriacane33
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,12 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
import pandas as pd
|
4 |
|
5 |
# Load the Question Answering model
|
6 |
@st.cache_resource
|
7 |
def load_qa_pipeline():
|
8 |
-
"""Load the QA pipeline with
|
9 |
-
|
10 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
-
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
12 |
-
return pipeline("question-answering", model=model, tokenizer=tokenizer)
|
13 |
|
14 |
qa_pipeline = load_qa_pipeline()
|
15 |
|
@@ -27,10 +24,8 @@ def find_best_context(question, dataset):
|
|
27 |
best_score = 0
|
28 |
best_context = None
|
29 |
|
30 |
-
for
|
31 |
-
# Access the 'text' column in the row
|
32 |
context_text = row['text']
|
33 |
-
# Simple heuristic: Count the number of overlapping words
|
34 |
overlap = len(set(question.lower().split()) & set(context_text.lower().split()))
|
35 |
if overlap > best_score:
|
36 |
best_score = overlap
|
@@ -39,26 +34,25 @@ def find_best_context(question, dataset):
|
|
39 |
return best_context
|
40 |
|
41 |
# Streamlit UI
|
42 |
-
st.title("SOP
|
43 |
-
st.markdown("
|
44 |
|
45 |
# User input
|
46 |
-
question = st.text_area("
|
47 |
|
48 |
# Generate answer
|
49 |
-
if st.button("
|
50 |
if question:
|
51 |
-
with st.spinner("
|
52 |
-
# Automatically find the most relevant context
|
53 |
context = find_best_context(question, dataset)
|
54 |
|
55 |
if context:
|
56 |
-
with st.spinner("
|
57 |
result = qa_pipeline(question=question, context=context)
|
58 |
-
st.success("
|
59 |
st.write(result["answer"])
|
60 |
-
st.write("
|
61 |
else:
|
62 |
-
st.warning("
|
63 |
else:
|
64 |
-
st.warning("
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
import pandas as pd
|
4 |
|
5 |
# Load the Question Answering model
|
6 |
@st.cache_resource
|
7 |
def load_qa_pipeline():
|
8 |
+
"""Load the QA pipeline with Rifky/Indobert-QA model."""
|
9 |
+
return pipeline("question-answering", model="Rifky/Indobert-QA", tokenizer="Rifky/Indobert-QA")
|
|
|
|
|
|
|
10 |
|
11 |
qa_pipeline = load_qa_pipeline()
|
12 |
|
|
|
24 |
best_score = 0
|
25 |
best_context = None
|
26 |
|
27 |
+
for _, row in dataset.iterrows():
|
|
|
28 |
context_text = row['text']
|
|
|
29 |
overlap = len(set(question.lower().split()) & set(context_text.lower().split()))
|
30 |
if overlap > best_score:
|
31 |
best_score = overlap
|
|
|
34 |
return best_context
|
35 |
|
36 |
# Streamlit UI
|
37 |
+
st.title("Sistem Penjawab Pertanyaan SOP dengan IndoBERT")
|
38 |
+
st.markdown("Ajukan pertanyaan seputar Prosedur Operasional Standar:")
|
39 |
|
40 |
# User input
|
41 |
+
question = st.text_area("Masukkan pertanyaan Anda:", "")
|
42 |
|
43 |
# Generate answer
|
44 |
+
if st.button("Dapatkan Jawaban"):
|
45 |
if question:
|
46 |
+
with st.spinner("Menemukan konteks yang paling relevan..."):
|
|
|
47 |
context = find_best_context(question, dataset)
|
48 |
|
49 |
if context:
|
50 |
+
with st.spinner("Menjawab pertanyaan Anda..."):
|
51 |
result = qa_pipeline(question=question, context=context)
|
52 |
+
st.success("Jawaban:")
|
53 |
st.write(result["answer"])
|
54 |
+
st.write("Skor Keyakinan:", result["score"])
|
55 |
else:
|
56 |
+
st.warning("Konteks yang relevan tidak ditemukan. Silakan coba pertanyaan lain.")
|
57 |
else:
|
58 |
+
st.warning("Silakan masukkan pertanyaan.")
|