huriacane33 commited on
Commit
b1d80a4
·
verified ·
1 Parent(s): 09ded81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -1,15 +1,12 @@
1
  import streamlit as st
2
- from transformers import AutoModelForQuestionAnswering, AutoTokenizer, 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 deepset/roberta-base-squad2 model."""
9
- model_name = "deepset/roberta-base-squad2"
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 index, row in dataset.iterrows():
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 Question Answering AI")
43
- st.markdown("Ask any question about Standard Operating Procedures:")
44
 
45
  # User input
46
- question = st.text_area("Enter your question:", "")
47
 
48
  # Generate answer
49
- if st.button("Get Answer"):
50
  if question:
51
- with st.spinner("Finding the best context..."):
52
- # Automatically find the most relevant context
53
  context = find_best_context(question, dataset)
54
 
55
  if context:
56
- with st.spinner("Answering your question..."):
57
  result = qa_pipeline(question=question, context=context)
58
- st.success("Answer:")
59
  st.write(result["answer"])
60
- st.write("Confidence Score:", result["score"])
61
  else:
62
- st.warning("No relevant context found. Please try rephrasing your question.")
63
  else:
64
- st.warning("Please enter a question.")
 
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.")