File size: 1,519 Bytes
3bf4f98
 
 
 
 
59966ca
3bf4f98
 
 
 
 
 
59966ca
 
3bf4f98
59966ca
 
 
3bf4f98
 
 
 
 
59966ca
3bf4f98
59966ca
 
 
3bf4f98
59966ca
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
import streamlit as st
import requests
from transformers import pipeline, BertTokenizer

# Function to generate answers using the BERT model
def generate_answers(chunks, question):
    # 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")

    # Concatenate chunks into a single text
    paper_text = ' '.join(chunks)

    # Generate answers for the question based on the entire context
    answer = model(question, paper_text)
    return answer['answer']

# Streamlit app
st.title("Research Paper Question Answering")

paper_link = st.text_input("Enter the link to the research paper (Arxiv link):")
question = st.text_input("Enter your question:")

if st.button("Generate Answer"):
    if not (paper_link and question):
        st.warning("Please provide both the paper link and the question.")
    else:
        # Download the research paper
        response = requests.get(paper_link)
        paper_text = response.text

        # Split the paper text into chunks of 512 words
        paper_chunks = [paper_text[i:i+512] for i in range(0, len(paper_text), 512)]

        # Generate answer based on chunks
        answer = generate_answers(paper_chunks, question)
        st.success("Answer generated successfully!")
        st.text("Generated Answer:")
        st.write(answer)