Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,34 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
|
|
|
|
7 |
|
8 |
# Set the title for the Streamlit app
|
9 |
-
st.title("Movie Trivia
|
10 |
|
11 |
-
# Text
|
12 |
-
|
|
|
13 |
|
14 |
-
def
|
15 |
-
#
|
16 |
-
|
17 |
-
return
|
18 |
|
19 |
if st.button("Get Answer"):
|
20 |
-
if
|
21 |
-
|
22 |
-
# Display the
|
23 |
st.subheader("Answer")
|
24 |
-
st.write(
|
25 |
else:
|
26 |
-
st.warning("Please enter
|
27 |
|
28 |
# Optionally, add instructions or information about the app
|
29 |
st.write("""
|
30 |
-
Enter a movie-related question above. The
|
31 |
""")
|
|
|
1 |
import streamlit as st
|
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 |
+
# Text inputs for the user
|
14 |
+
context = st.text_area("Enter the context (movie-related text):")
|
15 |
+
question = st.text_area("Enter your question:")
|
16 |
|
17 |
+
def generate_answer(question, context):
|
18 |
+
# Perform question answering
|
19 |
+
result = qa_pipeline(question=question, context=context)
|
20 |
+
return result['answer']
|
21 |
|
22 |
if st.button("Get Answer"):
|
23 |
+
if context and question:
|
24 |
+
generated_answer = generate_answer(question, context)
|
25 |
+
# Display the generated answer
|
26 |
st.subheader("Answer")
|
27 |
+
st.write(generated_answer)
|
28 |
else:
|
29 |
+
st.warning("Please enter both context and question.")
|
30 |
|
31 |
# Optionally, add instructions or information about the app
|
32 |
st.write("""
|
33 |
+
Enter a movie-related context and a question related to the context above. The model will provide the answer based on the context provided.
|
34 |
""")
|