Spaces:
Sleeping
Sleeping
| 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 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}") | |