sabssag commited on
Commit
2e550ae
·
verified ·
1 Parent(s): 50c7e7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -7,11 +7,16 @@ model_path = './QAModel' # Path to your fine-tuned model
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):
@@ -20,15 +25,15 @@ def generate_answer(question, 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
- """)
 
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 = 'context.txt' # Replace with your context file path
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
+ # Text input for the user question
 
20
  question = st.text_area("Enter your question:")
21
 
22
  def generate_answer(question, context):
 
25
  return result['answer']
26
 
27
  if st.button("Get Answer"):
28
+ if question:
29
+ generated_answer = generate_answer(question, default_context)
30
  # Display the generated answer
31
  st.subheader("Answer")
32
  st.write(generated_answer)
33
  else:
34
+ st.warning("Please enter a question.")
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 provided.
39
+ """)