Spaces:
Sleeping
Sleeping
File size: 1,460 Bytes
3bf4f98 |
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 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
import requests
from transformers import pipeline, BertTokenizer
# Function to generate answers using the BERT model
def generate_answers(questions, paper_link):
# Download the research paper
response = requests.get(paper_link)
paper_text = response.text
# Initialize the BERT tokenizer
tokenizer = BertTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
# Initialize the question-answering pipeline
model = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad")
# Generate answers for each question
answers = []
for question in questions.split(","):
inputs = tokenizer(question.strip(), paper_text, return_tensors="pt")
answer = model(**inputs)
answers.append(answer['answer'])
return '\n\n'.join(answers)
# Streamlit app
st.title("Research Paper Question Answering")
questions = st.text_input("Enter comma-separated questions:")
paper_link = st.text_input("Enter the link to the research paper (Arxiv link):")
if st.button("Generate Answers"):
if not (questions and paper_link):
st.warning("Please provide both questions and the paper link.")
else:
with st.spinner("Generating answers..."):
answers = generate_answers(questions, paper_link)
st.success("Answers generated successfully!")
st.text_area("Generated Answers", answers) |