Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,39 @@
|
|
| 1 |
-
import gradio
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
file.write(generated_text)
|
| 25 |
-
|
| 26 |
-
return generated_text
|
| 27 |
|
| 28 |
-
|
| 29 |
iface.launch()
|
|
|
|
| 1 |
+
import gradio
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
from transformers import pipeline
|
| 5 |
|
| 6 |
+
# Function to scrape information from a website
|
| 7 |
+
def scrape_website(prompt, website_link):
|
| 8 |
+
response = requests.get(website_link)
|
| 9 |
+
soup = BeautifulSoup(response.content, "html.parser")
|
| 10 |
+
|
| 11 |
+
# Implement your web scraping logic here
|
| 12 |
+
# Extract the desired information from the HTML
|
| 13 |
+
|
| 14 |
+
scraped_info = "Scraped information from the website"
|
| 15 |
+
return scraped_info
|
| 16 |
|
| 17 |
+
# Function to generate chatbot responses
|
| 18 |
+
def generate_chatbot_response(prompt):
|
| 19 |
+
chatbot = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
|
| 20 |
+
chatbot_response = chatbot(prompt, max_length=50, num_return_sequences=1)[0]["generated_text"]
|
| 21 |
+
return chatbot_response
|
| 22 |
|
| 23 |
+
# Function to handle the web app logic
|
| 24 |
+
def web_app(prompt, website_link):
|
| 25 |
+
scraped_info = scrape_website(prompt, website_link)
|
| 26 |
+
chatbot_response = generate_chatbot_response(prompt)
|
| 27 |
+
return {"Scraped Information": scraped_info, "Chatbot Response": chatbot_response}
|
| 28 |
|
| 29 |
+
# Create the Gradio interface
|
| 30 |
+
iface = gradio.Interface(
|
| 31 |
+
fn=web_app,
|
| 32 |
+
inputs=["text", "text"],
|
| 33 |
+
outputs=["text", "text"],
|
| 34 |
+
title="Web Scraping and Chatbot App",
|
| 35 |
+
description="Enter a prompt and a website link to scrape information and generate a chatbot response."
|
| 36 |
+
)
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Run the Gradio app
|
| 39 |
iface.launch()
|