ResearchPaperQA / app.py
dippatel1994's picture
Added app.py
3bf4f98 verified
raw
history blame
1.46 kB
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)