Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- ai_engine.py +25 -16
- requirements.txt +1 -1
ai_engine.py
CHANGED
|
@@ -1,36 +1,45 @@
|
|
| 1 |
-
import google.generativeai as genai
|
| 2 |
import os
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# Initialize the model (using the standard gemini-pro which is universally supported)
|
| 9 |
-
model = genai.GenerativeModel(
|
| 10 |
-
model_name='gemini-pro',
|
| 11 |
-
generation_config={"response_mime_type": "application/json"} # Forces perfect JSON!
|
| 12 |
-
)
|
| 13 |
|
| 14 |
def analyze_lead(name: str, company: str, company_summary: str) -> dict:
|
| 15 |
prompt = f"""
|
| 16 |
You are a B2B sales expert. Analyze this lead.
|
| 17 |
Lead: {name} at {company}. Info: {company_summary}
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
{{
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
}}
|
| 25 |
"""
|
| 26 |
|
| 27 |
try:
|
| 28 |
-
response =
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
# Fallback if something goes wrong
|
|
|
|
| 34 |
return {
|
| 35 |
"score": 0,
|
| 36 |
"score_reason": f"AI Error: {str(e)}",
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
+
from groq import Groq
|
| 4 |
|
| 5 |
+
# Initialize the Groq client
|
| 6 |
+
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def analyze_lead(name: str, company: str, company_summary: str) -> dict:
|
| 9 |
prompt = f"""
|
| 10 |
You are a B2B sales expert. Analyze this lead.
|
| 11 |
Lead: {name} at {company}. Info: {company_summary}
|
| 12 |
|
| 13 |
+
1. Score the lead from 1 to 10 based on how likely they are to need AI software automation.
|
| 14 |
+
(E.g., outdated businesses = high score, modern tech = lower score).
|
| 15 |
+
2. Write a 1-sentence reason for the score.
|
| 16 |
+
3. Write a short, highly personalized 100-word cold email offering our AI services to them. Start with Hi {name},. End by asking for a 10-min chat.
|
| 17 |
+
|
| 18 |
+
Output EXACTLY in this JSON format:
|
| 19 |
{{
|
| 20 |
+
"score": 8,
|
| 21 |
+
"score_reason": "They have a lot of manual processes...",
|
| 22 |
+
"cold_email": "Hi {name}..."
|
| 23 |
}}
|
| 24 |
"""
|
| 25 |
|
| 26 |
try:
|
| 27 |
+
response = client.chat.completions.create(
|
| 28 |
+
messages=[
|
| 29 |
+
{"role": "system", "content": "You are an expert B2B sales qualifier. Output ONLY a valid JSON object."},
|
| 30 |
+
{"role": "user", "content": prompt}
|
| 31 |
+
],
|
| 32 |
+
model="llama3-70b-8192",
|
| 33 |
+
response_format={"type": "json_object"}
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Parse the JSON returned by Llama 3
|
| 37 |
+
result = json.loads(response.choices[0].message.content)
|
| 38 |
+
return result
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
# Fallback if something goes wrong
|
| 42 |
+
print(f"Error calling Groq: {e}")
|
| 43 |
return {
|
| 44 |
"score": 0,
|
| 45 |
"score_reason": f"AI Error: {str(e)}",
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
-
|
| 4 |
supabase
|
| 5 |
requests
|
| 6 |
python-dotenv
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
+
groq
|
| 4 |
supabase
|
| 5 |
requests
|
| 6 |
python-dotenv
|