Spaces:
Sleeping
Sleeping
Added app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from transformers import pipeline, BertTokenizer
|
| 4 |
+
|
| 5 |
+
# Function to generate answers using the BERT model
|
| 6 |
+
def generate_answers(questions, paper_link):
|
| 7 |
+
# Download the research paper
|
| 8 |
+
response = requests.get(paper_link)
|
| 9 |
+
paper_text = response.text
|
| 10 |
+
|
| 11 |
+
# Initialize the BERT tokenizer
|
| 12 |
+
tokenizer = BertTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
|
| 13 |
+
|
| 14 |
+
# Initialize the question-answering pipeline
|
| 15 |
+
model = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad")
|
| 16 |
+
|
| 17 |
+
# Generate answers for each question
|
| 18 |
+
answers = []
|
| 19 |
+
for question in questions.split(","):
|
| 20 |
+
inputs = tokenizer(question.strip(), paper_text, return_tensors="pt")
|
| 21 |
+
answer = model(**inputs)
|
| 22 |
+
answers.append(answer['answer'])
|
| 23 |
+
|
| 24 |
+
return '\n\n'.join(answers)
|
| 25 |
+
|
| 26 |
+
# Streamlit app
|
| 27 |
+
st.title("Research Paper Question Answering")
|
| 28 |
+
|
| 29 |
+
questions = st.text_input("Enter comma-separated questions:")
|
| 30 |
+
paper_link = st.text_input("Enter the link to the research paper (Arxiv link):")
|
| 31 |
+
|
| 32 |
+
if st.button("Generate Answers"):
|
| 33 |
+
if not (questions and paper_link):
|
| 34 |
+
st.warning("Please provide both questions and the paper link.")
|
| 35 |
+
else:
|
| 36 |
+
with st.spinner("Generating answers..."):
|
| 37 |
+
answers = generate_answers(questions, paper_link)
|
| 38 |
+
st.success("Answers generated successfully!")
|
| 39 |
+
st.text_area("Generated Answers", answers)
|