Spaces:
Sleeping
Sleeping
Update company_content_generator.py
Browse files- company_content_generator.py +102 -92
company_content_generator.py
CHANGED
|
@@ -1,93 +1,103 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
import asyncio
|
| 3 |
-
from langchain_core.prompts import PromptTemplate
|
| 4 |
-
|
| 5 |
-
from crawl import marketing_crawling
|
| 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 |
-
|
| 43 |
-
#### **
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
**
|
| 69 |
-
**
|
| 70 |
-
**
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
**
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import asyncio
|
| 3 |
+
from langchain_core.prompts import PromptTemplate
|
| 4 |
+
|
| 5 |
+
from crawl import marketing_crawling
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
import subprocess
|
| 9 |
+
|
| 10 |
+
# Install Playwright browsers
|
| 11 |
+
try:
|
| 12 |
+
subprocess.run(["playwright", "install", "--with-deps"], check=True)
|
| 13 |
+
print("Playwright browsers installed successfully.")
|
| 14 |
+
except subprocess.CalledProcessError as e:
|
| 15 |
+
print(f"Error installing Playwright browsers: {e}")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
company_prompt_template = PromptTemplate.from_template("""
|
| 19 |
+
# Task
|
| 20 |
+
This is the scraped content from the company website. Read this content and extract the key information in an easy-to-read, professional format.
|
| 21 |
+
|
| 22 |
+
#**Instructions:**
|
| 23 |
+
- Focus on the most important details and present them in a structured, clear format.
|
| 24 |
+
- Follow the example below for formatting and style.
|
| 25 |
+
- Organize the content into clear sections such as:
|
| 26 |
+
- **About the Company**
|
| 27 |
+
- **Services Offered** (with sub-sections for each service)
|
| 28 |
+
- **Why Choose the Company** (highlight unique selling points and certifications)
|
| 29 |
+
- **Company Information** (contact details, address, and other relevant details)
|
| 30 |
+
- Avoid irrelevant details, redundant information, and generic text.
|
| 31 |
+
- Use professional, concise language that is easy to understand.
|
| 32 |
+
- Ensure consistency in formatting and tone.
|
| 33 |
+
|
| 34 |
+
#**Example:**
|
| 35 |
+
|
| 36 |
+
#### **About All Solar Works**
|
| 37 |
+
All Solar Works specializes in **solar panels, battery storage, EV chargers, and electrical services** across Sussex, UK. They offer expert installation and high-quality solutions to help customers save money on energy bills while reducing their carbon footprint.
|
| 38 |
+
|
| 39 |
+
----------
|
| 40 |
+
|
| 41 |
+
### **Services Offered**
|
| 42 |
+
|
| 43 |
+
#### **1. Solar Panels**
|
| 44 |
+
- Install various solar panel systems to fit different budgets.
|
| 45 |
+
- Helps customers reduce bills and enjoy long-term savings.
|
| 46 |
+
- **Complete Solar Panel System Package includes:**
|
| 47 |
+
- **X** kWp Solar PV System
|
| 48 |
+
- **X** W Aiko Panels
|
| 49 |
+
- **X** kW Hybrid Inverter
|
| 50 |
+
- **Online Monitoring, DNO application, Warranty, and MCS certification**
|
| 51 |
+
- Available **with or without battery storage**.
|
| 52 |
+
|
| 53 |
+
#### **2. Battery Storage**
|
| 54 |
+
- Certified **Fox ESS Elite Installer**, ensuring top performance and reliability.
|
| 55 |
+
- Stores excess solar energy for use at night or during low sunlight hours.
|
| 56 |
+
|
| 57 |
+
#### **3. EV Charging Solutions**
|
| 58 |
+
- Install home and workplace **EV chargers**.
|
| 59 |
+
- Compatible with **all Type-2 electric vehicles**.
|
| 60 |
+
- Includes a dedicated app for full control over charging.
|
| 61 |
+
|
| 62 |
+
#### **4. Electrical Services**
|
| 63 |
+
- Professional and reliable services, including:
|
| 64 |
+
- **Rewiring, consumer unit replacement, additional power points, and more.**
|
| 65 |
+
|
| 66 |
+
----------
|
| 67 |
+
|
| 68 |
+
### **Why Choose All Solar Works?**
|
| 69 |
+
**Certified Fox ESS Elite Installer** β Ensures optimal battery storage performance.
|
| 70 |
+
**Customizable Solar Solutions** β Tailored to individual energy needs.
|
| 71 |
+
**Energy Independence** β Reduce reliance on the grid and lower bills.
|
| 72 |
+
**Long-Term Savings** β Financially beneficial with eco-friendly advantages.
|
| 73 |
+
|
| 74 |
+
----------
|
| 75 |
+
|
| 76 |
+
### **Company Information**
|
| 77 |
+
**Company Name:** All Solar Works
|
| 78 |
+
**Location:** Edgehill Close, Worthing, West Sussex, BN XX
|
| 79 |
+
**Contact:** info@allsolarworks.com | +44 XXX XXXX
|
| 80 |
+
**Operating Hours:** Monday β Friday (9 AM β 5 PM), Saturday (10 AM β 2 PM)
|
| 81 |
+
|
| 82 |
+
----------
|
| 83 |
+
|
| 84 |
+
Use this format and structure when extracting the content from the website. Ensure the final output is clean, structured, and easy to understand.
|
| 85 |
+
|
| 86 |
+
----------
|
| 87 |
+
|
| 88 |
+
**Company Information:**
|
| 89 |
+
{company_information}
|
| 90 |
+
|
| 91 |
+
""")
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def company_content(llm, state):
|
| 95 |
+
url = state["url"]
|
| 96 |
+
if sys.platform == "win32":
|
| 97 |
+
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
| 98 |
+
content = asyncio.run(marketing_crawling(url))
|
| 99 |
+
prompt = company_prompt_template.invoke({"company_information": content})
|
| 100 |
+
response = llm.invoke(prompt)
|
| 101 |
+
print(response.content)
|
| 102 |
+
return {"company_information": response.content}
|
| 103 |
|