Spaces:
Running
Running
File size: 3,324 Bytes
8904a49 8f6177a 8904a49 e0cfa4a 8904a49 e0cfa4a 8f6177a 8904a49 b1dd8c0 8904a49 b1dd8c0 8904a49 8f6177a b1dd8c0 8f6177a b1dd8c0 8904a49 8f6177a 8904a49 8f6177a e0cfa4a 8904a49 8f6177a b1dd8c0 8904a49 e0cfa4a 8904a49 b1dd8c0 8904a49 b1dd8c0 8904a49 e0cfa4a 8904a49 b1dd8c0 8904a49 b1dd8c0 8904a49 |
1 2 3 4 5 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 94 |
import streamlit as st
import requests
import re
import time
# APIs
TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
# Genrate Ideas
def generate_startup_ideas(prompt, retries=3, delay=2):
url = "https://api.together.xyz/v1/completions"
headers = {
"Authorization": f"Bearer {TOGETHER_API_KEY}",
"Content-Type": "application/json"
}
data = {
"model": "mistralai/Mistral-7B-Instruct-v0.1",
"prompt": f"""
Suggest 3 unique startup ideas based on this interest: \"{prompt}\".
Each idea should be short, clear, and numbered like this:
1. [Idea Title]: [One-sentence description]
2. ...
""",
"max_tokens": 300,
"temperature": 0.7,
"top_p": 0.95
}
for attempt in range(retries):
try:
response = requests.post(url, headers=headers, json=data)
result = response.json()
if "choices" in result and result["choices"]:
raw_text = result["choices"][0].get("text", "").strip()
ideas = re.findall(r"\d+\.\s*(.*?):\s*(.*)", raw_text)
if ideas:
return [f"{i+1}. {title.strip()}: {desc.strip()}" for i, (title, desc) in enumerate(ideas)]
else:
print("β οΈ No valid ideas format. Raw output:", raw_text)
else:
print("β οΈ Unexpected API response:", result)
except Exception as e:
print(f"[Attempt {attempt+1}] Error: {e}")
time.sleep(delay)
return []
# For working on URLs
def market_research(query):
url = "https://google.serper.dev/search"
headers = {"X-API-KEY": SERPER_API_KEY}
data = {"q": query}
try:
res = requests.post(url, headers=headers, json=data)
results = res.json()
return [r["title"] + " - " + r["link"] for r in results.get("organic", [])[:5]]
except Exception as e:
print("Market research error:", e)
return ["β Market research failed."]
# Streamlit UI
st.set_page_config(page_title="Startup Co-Founder Agent", layout="centered")
st.title("π Startup Co-Founder Agent")
st.write("Get startup ideas + instant market research. Free & AI-powered.")
user_prompt = st.text_input("What are you interested in building a startup around?", "AI for education")
if st.button("Generate Startup Ideas"):
if not TOGETHER_API_KEY or not SERPER_API_KEY:
st.error("API keys are missing. Set them in environment or Hugging Face Secrets.")
else:
with st.spinner("Brewing ideas with HuggingFace GPUs and coffee... βπ€"):
ideas = generate_startup_ideas(user_prompt)
if not ideas:
st.error("Still no ideas. Maybe try again in a few seconds.")
else:
st.subheader("π‘ Startup Ideas")
for idea in ideas:
st.markdown(f"- {idea}")
st.subheader("π Market Research")
for idea in ideas:
title = idea.split(":")[0].strip()
st.markdown(f"**π {title}**")
results = market_research(title)
for r in results:
st.markdown(f"- {r}")
|