Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,21 +2,24 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Define the path to the saved model
|
5 |
-
model_path = './QAModel'
|
6 |
|
7 |
# Load the question-answering pipeline
|
8 |
qa_pipeline = pipeline("question-answering", model=model_path, tokenizer=model_path)
|
9 |
|
10 |
-
# Load the context from a file
|
11 |
-
context_file = 'contexts.txt'
|
12 |
-
|
13 |
-
with open(context_file, 'r', encoding='utf-8') as f:
|
14 |
-
default_context = f.read()
|
15 |
-
|
16 |
# Set the title for the Streamlit app
|
17 |
st.title("Movie Trivia Question Answering")
|
18 |
|
19 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
question = st.text_area("Enter your question:")
|
21 |
|
22 |
def generate_answer(question, context):
|
@@ -26,7 +29,7 @@ def generate_answer(question, context):
|
|
26 |
|
27 |
if st.button("Get Answer"):
|
28 |
if question:
|
29 |
-
generated_answer = generate_answer(question,
|
30 |
# Display the generated answer
|
31 |
st.subheader("Answer")
|
32 |
st.write(generated_answer)
|
@@ -35,5 +38,5 @@ if st.button("Get Answer"):
|
|
35 |
|
36 |
# Optionally, add instructions or information about the app
|
37 |
st.write("""
|
38 |
-
Enter a question related to the provided movie-related context above. The model will provide the answer based on the context
|
39 |
-
""")
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Define the path to the saved model
|
5 |
+
model_path = './QAModel' # Path to your fine-tuned model
|
6 |
|
7 |
# Load the question-answering pipeline
|
8 |
qa_pipeline = pipeline("question-answering", model=model_path, tokenizer=model_path)
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# Set the title for the Streamlit app
|
11 |
st.title("Movie Trivia Question Answering")
|
12 |
|
13 |
+
# Load the context from a predefined file
|
14 |
+
context_file_path = '/contexts.txt' # Replace with the actual path to your context file
|
15 |
+
with open(context_file_path, 'r') as file:
|
16 |
+
context = file.read()
|
17 |
+
|
18 |
+
# Display the context to the user
|
19 |
+
st.subheader("Context (movie-related text)")
|
20 |
+
st.write(context)
|
21 |
+
|
22 |
+
# Text input for the user to enter the question
|
23 |
question = st.text_area("Enter your question:")
|
24 |
|
25 |
def generate_answer(question, context):
|
|
|
29 |
|
30 |
if st.button("Get Answer"):
|
31 |
if question:
|
32 |
+
generated_answer = generate_answer(question, context)
|
33 |
# Display the generated answer
|
34 |
st.subheader("Answer")
|
35 |
st.write(generated_answer)
|
|
|
38 |
|
39 |
# Optionally, add instructions or information about the app
|
40 |
st.write("""
|
41 |
+
Enter a question related to the provided movie-related context above. The model will provide the answer based on the context.
|
42 |
+
""")
|