Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 3 |
+
|
| 4 |
+
# Load the fine-tuned model and tokenizer
|
| 5 |
+
model_name = "ibrahimgiki/qa_facebook_bart_base"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Define a custom question-answering pipeline
|
| 10 |
+
qa_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
| 11 |
+
|
| 12 |
+
# Streamlit app layout
|
| 13 |
+
st.title("Question Answering with BART")
|
| 14 |
+
|
| 15 |
+
# Text area for the user to input a question
|
| 16 |
+
question = st.text_area("Enter your question:")
|
| 17 |
+
|
| 18 |
+
# Submit button
|
| 19 |
+
if st.button("Submit"):
|
| 20 |
+
if question:
|
| 21 |
+
# Perform inference using the pipeline
|
| 22 |
+
result = qa_pipeline(question)
|
| 23 |
+
answer = result[0]['generated_text']
|
| 24 |
+
|
| 25 |
+
# Display the answer
|
| 26 |
+
st.write("**Answer:**", answer)
|
| 27 |
+
else:
|
| 28 |
+
st.write("Please enter a question.")
|