abdulllah01 commited on
Commit
4d7cf03
·
verified ·
1 Parent(s): 49b7cf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
3
+
4
+ # Load the model and tokenizer from your Hugging Face Hub repository
5
+ model_checkpoint = "abdulllah01/checkpoints" # Replace with your actual checkpoint
6
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
7
+ model = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint)
8
+
9
+ # Create a pipeline for question answering
10
+ qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
11
+
12
+ # Streamlit UI setup
13
+ st.title("Question Answering App")
14
+ st.write("Enter a context and ask a question based on that context.")
15
+
16
+ # Text area for context input
17
+ context = st.text_area("Context:", "")
18
+
19
+ # Text input for the question
20
+ question = st.text_input("Question:", "")
21
+
22
+ if st.button("Get Answer"):
23
+ if context and question:
24
+ # Generate the answer using the pipeline
25
+ result = qa_pipeline(question=question, context=context)
26
+ answer = result['answer']
27
+ st.write("**Answer:**", answer)
28
+ else:
29
+ st.write("Please enter both context and question.")