Spaces:
Running
Running
Create old code.py
Browse files- old code.py +93 -0
old code.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import re
|
4 |
+
import time
|
5 |
+
|
6 |
+
# APIs
|
7 |
+
TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
|
8 |
+
SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
|
9 |
+
|
10 |
+
# Genrate Ideas
|
11 |
+
def generate_startup_ideas(prompt, retries=3, delay=2):
|
12 |
+
url = "https://api.together.xyz/v1/completions"
|
13 |
+
headers = {
|
14 |
+
"Authorization": f"Bearer {TOGETHER_API_KEY}",
|
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:
|
22 |
+
1. [Idea Title]: [One-sentence description]
|
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 |
+
|
51 |
+
return []
|
52 |
+
|
53 |
+
# For working on URLs
|
54 |
+
def market_research(query):
|
55 |
+
url = "https://google.serper.dev/search"
|
56 |
+
headers = {"X-API-KEY": SERPER_API_KEY}
|
57 |
+
data = {"q": query}
|
58 |
+
try:
|
59 |
+
res = requests.post(url, headers=headers, json=data)
|
60 |
+
results = res.json()
|
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:
|
85 |
+
st.markdown(f"- {idea}")
|
86 |
+
|
87 |
+
st.subheader("π Market Research")
|
88 |
+
for idea in ideas:
|
89 |
+
title = idea.split(":")[0].strip()
|
90 |
+
st.markdown(f"**π {title}**")
|
91 |
+
results = market_research(title)
|
92 |
+
for r in results:
|
93 |
+
st.markdown(f"- {r}")
|