sabssag commited on
Commit
416be73
·
verified ·
1 Parent(s): c705de2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -1,34 +1,31 @@
1
  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 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("Generated 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
  """)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Load the conversational pipeline
5
+ model_name = "QAModel"
6
+ chatbot_pipeline = pipeline("conversational", model=model_name, tokenizer=model_name)
 
 
7
 
8
  # Set the title for the Streamlit app
9
+ st.title("Movie Trivia Chatbot")
10
 
11
+ # Text input for the user
12
+ user_input = st.text_area("Ask a movie trivia question:")
 
13
 
14
+ def get_response(user_input):
15
+ # Generate response
16
+ conversation = chatbot_pipeline(user_input)
17
+ return conversation[0]['generated_text']
18
 
19
  if st.button("Get Answer"):
20
+ if user_input:
21
+ response = get_response(user_input)
22
+ # Display the response
23
+ st.subheader("Answer")
24
+ st.write(response)
25
  else:
26
+ st.warning("Please enter a question.")
27
 
28
  # Optionally, add instructions or information about the app
29
  st.write("""
30
+ Enter a movie-related question above. The chatbot will provide an answer based on its training.
31
  """)