import streamlit as st from transformers import pipeline # Define the path to the saved model model_path = './QAModel' # Path to your fine-tuned model # Load the question-answering pipeline qa_pipeline = pipeline("question-answering", model=model_path, tokenizer=model_path) # Set the title for the Streamlit app st.title("Movie Trivia Question Answering") # Text inputs for the user context = st.text_area("Enter the context (movie-related text):") question = st.text_area("Enter your question:") def generate_answer(question, context): # Perform question answering result = qa_pipeline(question=question, context=context) return result['answer'] if st.button("Get Answer"): if context and question: generated_answer = generate_answer(question, context) # Display the generated answer st.subheader("Answer") st.write(generated_answer) else: st.warning("Please enter both context and question.") # Optionally, add instructions or information about the app st.write(""" Enter a movie-related context and a question related to the context above. The model will provide the answer based on the context provided. """)