File size: 1,027 Bytes
f31e270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Step 2: Import necessary libraries
import streamlit as st
from transformers import pipeline

# Step 3: Load pre-trained model and tokenizer
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="distilbert-base-cased")

# Step 4: Define Streamlit app
def main():
    # Set app title
    st.title("Question Answering with ALBERT")

    # Input context
    context = st.text_area("Enter the context:")

    # Input questions
    num_questions = st.number_input("Enter the number of questions:", min_value=1, max_value=10, step=1)
    questions = [st.text_input(f"Enter question {i + 1}:") for i in range(num_questions)]

    # Ask questions and display answers
    if st.button("Get Answers"):
        for i, question in enumerate(questions):
            if question:
                answer = qa_pipeline({"context": context, "question": question})
                st.write(f"Answer {i + 1}: {answer['answer']}")

# Step 5: Run Streamlit app
if __name__ == "__main__":
    main()