Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,11 @@ import requests
|
|
3 |
import re
|
4 |
import time
|
5 |
|
6 |
-
# --- π API KEYS
|
7 |
TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
|
8 |
SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
|
9 |
|
10 |
-
# --- π¬
|
11 |
def generate_startup_ideas(prompt, retries=3, delay=2):
|
12 |
url = "https://api.together.xyz/v1/completions"
|
13 |
headers = {
|
@@ -15,7 +15,7 @@ def generate_startup_ideas(prompt, retries=3, delay=2):
|
|
15 |
"Content-Type": "application/json"
|
16 |
}
|
17 |
data = {
|
18 |
-
"model": "mistralai/Mistral-7B-Instruct",
|
19 |
"prompt": f"""
|
20 |
Suggest 3 unique startup ideas based on this interest: \"{prompt}\".
|
21 |
Each idea should be short, clear, and numbered like this:
|
@@ -23,22 +23,28 @@ Each idea should be short, clear, and numbered like this:
|
|
23 |
2. ...
|
24 |
""",
|
25 |
"max_tokens": 300,
|
26 |
-
"temperature": 0.7
|
|
|
27 |
}
|
28 |
|
29 |
for attempt in range(retries):
|
30 |
try:
|
31 |
response = requests.post(url, headers=headers, json=data)
|
32 |
result = response.json()
|
33 |
-
print("API response:", result)
|
34 |
|
35 |
if "choices" in result and result["choices"]:
|
36 |
raw_text = result["choices"][0].get("text", "").strip()
|
37 |
ideas = re.findall(r"\d+\.\s*(.*?):\s*(.*)", raw_text)
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
except Exception as e:
|
41 |
-
print(f"[
|
42 |
|
43 |
time.sleep(delay)
|
44 |
|
@@ -55,23 +61,24 @@ def market_research(query):
|
|
55 |
return [r["title"] + " - " + r["link"] for r in results.get("organic", [])[:5]]
|
56 |
except Exception as e:
|
57 |
print("Market research error:", e)
|
58 |
-
return ["
|
59 |
|
60 |
-
# --- π
|
61 |
st.set_page_config(page_title="Startup Co-Founder Agent", layout="centered")
|
62 |
st.title("π Startup Co-Founder Agent")
|
63 |
-
st.write("Get startup ideas + instant market research
|
64 |
|
65 |
user_prompt = st.text_input("What are you interested in building a startup around?", "AI for education")
|
66 |
|
67 |
if st.button("Generate Startup Ideas"):
|
68 |
if not TOGETHER_API_KEY or not SERPER_API_KEY:
|
69 |
-
st.error("API keys are
|
70 |
else:
|
71 |
-
with st.spinner("
|
72 |
ideas = generate_startup_ideas(user_prompt)
|
|
|
73 |
if not ideas:
|
74 |
-
st.error("Still no ideas.
|
75 |
else:
|
76 |
st.subheader("π‘ Startup Ideas")
|
77 |
for idea in ideas:
|
|
|
3 |
import re
|
4 |
import time
|
5 |
|
6 |
+
# --- π API KEYS ---
|
7 |
TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
|
8 |
SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
|
9 |
|
10 |
+
# --- π¬ Generate Startup Ideas ---
|
11 |
def generate_startup_ideas(prompt, retries=3, delay=2):
|
12 |
url = "https://api.together.xyz/v1/completions"
|
13 |
headers = {
|
|
|
15 |
"Content-Type": "application/json"
|
16 |
}
|
17 |
data = {
|
18 |
+
"model": "mistralai/Mistral-7B-Instruct-v0.1",
|
19 |
"prompt": f"""
|
20 |
Suggest 3 unique startup ideas based on this interest: \"{prompt}\".
|
21 |
Each idea should be short, clear, and numbered like this:
|
|
|
23 |
2. ...
|
24 |
""",
|
25 |
"max_tokens": 300,
|
26 |
+
"temperature": 0.7,
|
27 |
+
"top_p": 0.95
|
28 |
}
|
29 |
|
30 |
for attempt in range(retries):
|
31 |
try:
|
32 |
response = requests.post(url, headers=headers, json=data)
|
33 |
result = response.json()
|
|
|
34 |
|
35 |
if "choices" in result and result["choices"]:
|
36 |
raw_text = result["choices"][0].get("text", "").strip()
|
37 |
ideas = re.findall(r"\d+\.\s*(.*?):\s*(.*)", raw_text)
|
38 |
+
if ideas:
|
39 |
+
return [f"{i+1}. {title.strip()}: {desc.strip()}" for i, (title, desc) in enumerate(ideas)]
|
40 |
+
else:
|
41 |
+
print("β οΈ No valid ideas format. Raw output:", raw_text)
|
42 |
+
|
43 |
+
else:
|
44 |
+
print("β οΈ Unexpected API response:", result)
|
45 |
|
46 |
except Exception as e:
|
47 |
+
print(f"[Attempt {attempt+1}] Error: {e}")
|
48 |
|
49 |
time.sleep(delay)
|
50 |
|
|
|
61 |
return [r["title"] + " - " + r["link"] for r in results.get("organic", [])[:5]]
|
62 |
except Exception as e:
|
63 |
print("Market research error:", e)
|
64 |
+
return ["β Market research failed."]
|
65 |
|
66 |
+
# --- π Streamlit UI ---
|
67 |
st.set_page_config(page_title="Startup Co-Founder Agent", layout="centered")
|
68 |
st.title("π Startup Co-Founder Agent")
|
69 |
+
st.write("Get startup ideas + instant market research. Free & AI-powered.")
|
70 |
|
71 |
user_prompt = st.text_input("What are you interested in building a startup around?", "AI for education")
|
72 |
|
73 |
if st.button("Generate Startup Ideas"):
|
74 |
if not TOGETHER_API_KEY or not SERPER_API_KEY:
|
75 |
+
st.error("API keys are missing. Set them in environment or Hugging Face Secrets.")
|
76 |
else:
|
77 |
+
with st.spinner("Brewing ideas with GPUs and coffee... βπ€"):
|
78 |
ideas = generate_startup_ideas(user_prompt)
|
79 |
+
|
80 |
if not ideas:
|
81 |
+
st.error("Still no ideas. Maybe try again in a few seconds.")
|
82 |
else:
|
83 |
st.subheader("π‘ Startup Ideas")
|
84 |
for idea in ideas:
|