Spaces:
Sleeping
Sleeping
# 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() |