auh11 commited on
Commit
f31e270
1 Parent(s): ae3a68a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Step 2: Import necessary libraries
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+
5
+ # Step 3: Load pre-trained model and tokenizer
6
+ qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="distilbert-base-cased")
7
+
8
+ # Step 4: Define Streamlit app
9
+ def main():
10
+ # Set app title
11
+ st.title("Question Answering with ALBERT")
12
+
13
+ # Input context
14
+ context = st.text_area("Enter the context:")
15
+
16
+ # Input questions
17
+ num_questions = st.number_input("Enter the number of questions:", min_value=1, max_value=10, step=1)
18
+ questions = [st.text_input(f"Enter question {i + 1}:") for i in range(num_questions)]
19
+
20
+ # Ask questions and display answers
21
+ if st.button("Get Answers"):
22
+ for i, question in enumerate(questions):
23
+ if question:
24
+ answer = qa_pipeline({"context": context, "question": question})
25
+ st.write(f"Answer {i + 1}: {answer['answer']}")
26
+
27
+ # Step 5: Run Streamlit app
28
+ if __name__ == "__main__":
29
+ main()