|
from transformers import pipeline |
|
from bs4 import BeautifulSoup |
|
import requests |
|
import gradio as gr |
|
|
|
def extract_text_from_url(url): |
|
response = requests.get(url) |
|
soup = BeautifulSoup(response.text, 'html.parser') |
|
return soup.get_text() |
|
|
|
def answer_question(context, question): |
|
qa_pipeline = pipeline("question-answering") |
|
answer = qa_pipeline({ |
|
'context': context, |
|
'question': question |
|
}) |
|
return answer['answer'] |
|
|
|
def app(url, question): |
|
webpage_text = extract_text_from_url(url) |
|
answer = answer_question(webpage_text, question) |
|
return answer |
|
|
|
iface = gr.Interface(fn=app, inputs=["text", "text"], outputs="text") |
|
iface.launch() |
|
|