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) # Load the context from a file context_file = 'context.txt' # Replace with your context file path with open(context_file, 'r', encoding='utf-8') as f: default_context = f.read() # Set the title for the Streamlit app st.title("Movie Trivia Question Answering") # Text input for the user question 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 question: generated_answer = generate_answer(question, default_context) # Display the generated answer st.subheader("Answer") st.write(generated_answer) else: st.warning("Please enter a question.") # Optionally, add instructions or information about the app st.write(""" Enter a question related to the provided movie-related context above. The model will provide the answer based on the context provided. """)