MarcosRodrigo commited on
Commit
ada589a
1 Parent(s): df0eb79

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained model and tokenizer
5
+ qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
6
+
7
+ def answer_question(context: str, question: str) -> str:
8
+ result = qa_pipeline(question=question, context=context)
9
+ return result['answer']
10
+
11
+ # Streamlit app
12
+ st.title("Question-Answering Bot")
13
+ st.write("Enter the context text and ask a question about it.")
14
+
15
+ context = st.text_area("Context", height=300)
16
+ question = st.text_input("Question")
17
+
18
+ if st.button("Get Answer"):
19
+ if context and question:
20
+ answer = answer_question(context, question)
21
+ st.write(f"**Question:** {question}")
22
+ st.write(f"**Answer:** {answer}")
23
+ else:
24
+ st.write("Please enter both the context and the question.")