terra1 / app.py
flatindo's picture
Update app.py
624a82f
raw
history blame
1.35 kB
import gradio
import requests
from bs4 import BeautifulSoup
from transformers import pipeline
# Function to scrape information from a website
def scrape_website(prompt, website_link):
response = requests.get(website_link)
soup = BeautifulSoup(response.content, "html.parser")
# Implement your web scraping logic here
# Extract the desired information from the HTML
scraped_info = "Scraped information from the website"
return scraped_info
# Function to generate chatbot responses
def generate_chatbot_response(prompt):
chatbot = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
chatbot_response = chatbot(prompt, max_length=50, num_return_sequences=1)[0]["generated_text"]
return chatbot_response
# Function to handle the web app logic
def web_app(prompt, website_link):
scraped_info = scrape_website(prompt, website_link)
chatbot_response = generate_chatbot_response(prompt)
return {"Scraped Information": scraped_info, "Chatbot Response": chatbot_response}
# Create the Gradio interface
iface = gradio.Interface(
fn=web_app,
inputs=["text", "text"],
outputs=["text", "text"],
title="Web Scraping and Chatbot App",
description="Enter a prompt and a website link to scrape information and generate a chatbot response."
)
# Run the Gradio app
iface.launch()