flatindo commited on
Commit
624a82f
·
1 Parent(s): 607f131

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -23
app.py CHANGED
@@ -1,29 +1,39 @@
1
- import gradio as gr
2
- import torch
3
- from transformers import GPT2Tokenizer, GPT2LMHeadModel
4
- import subprocess
5
 
6
- #upgrade_command = "python -m pip install --upgrade pip"
 
 
 
 
 
 
 
 
 
7
 
8
- # Run the command
9
- #subprocess.run(upgrade_command, shell=True)
 
 
 
10
 
11
- # Load the pre-trained GPT-2 model and tokenizer
12
- model_name = "AIDC-ai-business/Marcoroni-70B" # You can change this to another model if needed
13
- tokenizer = GPT2Tokenizer.from_pretrained(model_name)
14
- model = GPT2LMHeadModel.from_pretrained(model_name)
 
15
 
16
- def generate_text(prompt):
17
- # Encode the input text and generate a continuation
18
- input_ids = tokenizer.encode(prompt, return_tensors="pt")
19
- output = model.generate(input_ids, max_length=100, num_return_sequences=1, pad_token_id=50256)
20
- generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
21
-
22
- # Save the generated text to a text file
23
- with open("generated_text.txt", "w") as file:
24
- file.write(generated_text)
25
-
26
- return generated_text
27
 
28
- iface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
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()