pradeepsengarr commited on
Commit
8904a49
Β·
verified Β·
1 Parent(s): 77b8ae0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🧠 Streamlit App: Startup Co-Founder Agent (for Hugging Face Spaces)
2
+
3
+ import streamlit as st
4
+ import requests
5
+ import re
6
+ import os
7
+
8
+ # --- πŸ”‘ API KEYS FROM ENVIRONMENT (Set in Hugging Face Space settings) ---
9
+ TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
10
+ SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
11
+
12
+ # --- πŸ’¬ LLM: Generate Structured Startup Ideas ---
13
+ def generate_startup_ideas(prompt):
14
+ url = "https://api.together.xyz/v1/completions"
15
+ headers = {
16
+ "Authorization": f"Bearer {TOGETHER_API_KEY}",
17
+ "Content-Type": "application/json"
18
+ }
19
+ data = {
20
+ "model": "mistralai/Mistral-7B-Instruct-v0.1",
21
+ "prompt": f"""
22
+ Suggest 3 unique startup ideas based on this interest: \"{prompt}\".
23
+ Each idea should be short, clear, and numbered like this:
24
+ 1. [Idea Title]: [One-sentence description]
25
+ 2. ...
26
+ """,
27
+ "max_tokens": 300,
28
+ "temperature": 0.7
29
+ }
30
+ response = requests.post(url, headers=headers, json=data)
31
+ result = response.json()
32
+
33
+ if "choices" not in result:
34
+ return []
35
+
36
+ raw_text = result["choices"][0].get("text", "").strip()
37
+ ideas = re.findall(r"\d+\.\s*(.*?):\s*(.*)", raw_text)
38
+ return [f"{i+1}. {title.strip()}: {desc.strip()}" for i, (title, desc) in enumerate(ideas)]
39
+
40
+ # --- πŸ” Market Research ---
41
+ def market_research(query):
42
+ url = "https://google.serper.dev/search"
43
+ headers = {"X-API-KEY": SERPER_API_KEY}
44
+ data = {"q": query}
45
+ res = requests.post(url, headers=headers, json=data)
46
+ results = res.json()
47
+ return [r["title"] + " - " + r["link"] for r in results.get("organic", [])[:5]]
48
+
49
+ # --- 🌐 STREAMLIT UI ---
50
+ st.set_page_config(page_title="Startup Co-Founder Agent", layout="centered")
51
+ st.title("πŸš€ Startup Co-Founder Agent")
52
+ st.write("Get startup ideas + instant market research with free AI tools!")
53
+
54
+ user_prompt = st.text_input("What are you interested in building a startup around?", "AI for education")
55
+
56
+ if st.button("Generate Startup Ideas"):
57
+ if not TOGETHER_API_KEY or not SERPER_API_KEY:
58
+ st.error("API keys are not set. Please configure them in your Hugging Face Space secrets.")
59
+ else:
60
+ with st.spinner("Generating ideas and researching..."):
61
+ ideas = generate_startup_ideas(user_prompt)
62
+ if not ideas:
63
+ st.error("No startup ideas generated. Check API keys or try again.")
64
+ else:
65
+ st.subheader("πŸ’‘ Startup Ideas")
66
+ for idea in ideas:
67
+ st.markdown(f"- {idea}")
68
+
69
+ st.subheader("πŸ” Market Research")
70
+ for idea in ideas:
71
+ title = idea.split(":")[0].strip()
72
+ st.markdown(f"**πŸ“Œ {title}**")
73
+ results = market_research(title)
74
+ for r in results:
75
+ st.markdown(f"- {r}")