agriculture-qa / app.py
ibrahimgiki's picture
Update app.py
a13d9e1 verified
raw
history blame contribute delete
No virus
922 Bytes
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
# Load the fine-tuned model and tokenizer
model_name = "ibrahimgiki/qa_facebook_bart_base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
# Define a custom question-answering pipeline
qa_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
# Streamlit app layout
st.title("Agriculture Question Answering with BART")
# Text area for the user to input a question
question = st.text_area("Enter your question:")
# Submit button
if st.button("Submit"):
if question:
# Perform inference using the pipeline
result = qa_pipeline(question)
answer = result[0]['generated_text']
# Display the answer
st.write("**Answer:**", answer)
else:
st.write("Please enter a question.")