Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,21 @@
|
|
| 1 |
-
# Trying to explore new Agentic AI
|
| 2 |
-
|
| 3 |
import streamlit as st
|
| 4 |
import requests
|
| 5 |
import re
|
| 6 |
-
import
|
| 7 |
|
| 8 |
-
#
|
| 9 |
TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
|
| 10 |
SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
|
| 11 |
|
| 12 |
-
#
|
| 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
|
| 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:
|
|
@@ -27,26 +25,39 @@ Each idea should be short, clear, and numbered like this:
|
|
| 27 |
"max_tokens": 300,
|
| 28 |
"temperature": 0.7
|
| 29 |
}
|
| 30 |
-
response = requests.post(url, headers=headers, json=data)
|
| 31 |
-
result = response.json()
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
#
|
| 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!")
|
|
@@ -55,12 +66,12 @@ user_prompt = st.text_input("What are you interested in building a startup aroun
|
|
| 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
|
| 59 |
else:
|
| 60 |
-
with st.spinner("
|
| 61 |
ideas = generate_startup_ideas(user_prompt)
|
| 62 |
if not ideas:
|
| 63 |
-
st.error("
|
| 64 |
else:
|
| 65 |
st.subheader("π‘ Startup Ideas")
|
| 66 |
for idea in ideas:
|
|
@@ -73,3 +84,84 @@ if st.button("Generate Startup Ideas"):
|
|
| 73 |
results = market_research(title)
|
| 74 |
for r in results:
|
| 75 |
st.markdown(f"- {r}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
+
# --- π API KEYS (replace with env vars or Hugging Face secrets in production) ---
|
| 7 |
TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
|
| 8 |
SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
|
| 9 |
|
| 10 |
+
# --- π¬ LLM: Generate Structured Startup 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",
|
| 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:
|
|
|
|
| 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 |
+
return [f"{i+1}. {title.strip()}: {desc.strip()}" for i, (title, desc) in enumerate(ideas)]
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"[Retry {attempt+1}] Error:", e)
|
| 42 |
|
| 43 |
+
time.sleep(delay)
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
return []
|
| 46 |
+
|
| 47 |
+
# --- π Market Research ---
|
| 48 |
def market_research(query):
|
| 49 |
url = "https://google.serper.dev/search"
|
| 50 |
headers = {"X-API-KEY": SERPER_API_KEY}
|
| 51 |
data = {"q": query}
|
| 52 |
+
try:
|
| 53 |
+
res = requests.post(url, headers=headers, json=data)
|
| 54 |
+
results = res.json()
|
| 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 ["Failed to fetch market research."]
|
| 59 |
|
| 60 |
+
# --- π STREAMLIT UI ---
|
| 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 with free AI tools!")
|
|
|
|
| 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 not set. Please configure them.")
|
| 70 |
else:
|
| 71 |
+
with st.spinner("Cooking up ideas and doing some Googling... π³"):
|
| 72 |
ideas = generate_startup_ideas(user_prompt)
|
| 73 |
if not ideas:
|
| 74 |
+
st.error("Still no ideas. Please try again later!")
|
| 75 |
else:
|
| 76 |
st.subheader("π‘ Startup Ideas")
|
| 77 |
for idea in ideas:
|
|
|
|
| 84 |
results = market_research(title)
|
| 85 |
for r in results:
|
| 86 |
st.markdown(f"- {r}")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
# # Trying to explore new Agentic AI
|
| 94 |
+
|
| 95 |
+
# import streamlit as st
|
| 96 |
+
# import requests
|
| 97 |
+
# import re
|
| 98 |
+
# import os
|
| 99 |
+
|
| 100 |
+
# # APIs that i used
|
| 101 |
+
# TOGETHER_API_KEY = "tgp_v1_ZytvDbMu9PMwIlnBZEfYSq9nzJAYwS0MecjY9Kt7RxE"
|
| 102 |
+
# SERPER_API_KEY = "75f06519187851ad63486c3012b34c5e0e6501f1"
|
| 103 |
+
|
| 104 |
+
# # Prompting or we can say basix structure
|
| 105 |
+
# def generate_startup_ideas(prompt):
|
| 106 |
+
# url = "https://api.together.xyz/v1/completions"
|
| 107 |
+
# headers = {
|
| 108 |
+
# "Authorization": f"Bearer {TOGETHER_API_KEY}",
|
| 109 |
+
# "Content-Type": "application/json"
|
| 110 |
+
# }
|
| 111 |
+
# data = {
|
| 112 |
+
# "model": "mistralai/Mistral-7B-Instruct-v0.1",
|
| 113 |
+
# "prompt": f"""
|
| 114 |
+
# Suggest 3 unique startup ideas based on this interest: \"{prompt}\".
|
| 115 |
+
# Each idea should be short, clear, and numbered like this:
|
| 116 |
+
# 1. [Idea Title]: [One-sentence description]
|
| 117 |
+
# 2. ...
|
| 118 |
+
# """,
|
| 119 |
+
# "max_tokens": 300,
|
| 120 |
+
# "temperature": 0.7
|
| 121 |
+
# }
|
| 122 |
+
# response = requests.post(url, headers=headers, json=data)
|
| 123 |
+
# result = response.json()
|
| 124 |
+
|
| 125 |
+
# if "choices" not in result:
|
| 126 |
+
# return []
|
| 127 |
+
|
| 128 |
+
# raw_text = result["choices"][0].get("text", "").strip()
|
| 129 |
+
# ideas = re.findall(r"\d+\.\s*(.*?):\s*(.*)", raw_text)
|
| 130 |
+
# return [f"{i+1}. {title.strip()}: {desc.strip()}" for i, (title, desc) in enumerate(ideas)]
|
| 131 |
+
|
| 132 |
+
# # For the url
|
| 133 |
+
# def market_research(query):
|
| 134 |
+
# url = "https://google.serper.dev/search"
|
| 135 |
+
# headers = {"X-API-KEY": SERPER_API_KEY}
|
| 136 |
+
# data = {"q": query}
|
| 137 |
+
# res = requests.post(url, headers=headers, json=data)
|
| 138 |
+
# results = res.json()
|
| 139 |
+
# return [r["title"] + " - " + r["link"] for r in results.get("organic", [])[:5]]
|
| 140 |
+
|
| 141 |
+
# # For UI
|
| 142 |
+
# st.set_page_config(page_title="Startup Co-Founder Agent", layout="centered")
|
| 143 |
+
# st.title("π Startup Co-Founder Agent")
|
| 144 |
+
# st.write("Get startup ideas + instant market research with free AI tools!")
|
| 145 |
+
|
| 146 |
+
# user_prompt = st.text_input("What are you interested in building a startup around?", "AI for education")
|
| 147 |
+
|
| 148 |
+
# if st.button("Generate Startup Ideas"):
|
| 149 |
+
# if not TOGETHER_API_KEY or not SERPER_API_KEY:
|
| 150 |
+
# st.error("API keys are not set. Please configure them in your Hugging Face Space secrets.")
|
| 151 |
+
# else:
|
| 152 |
+
# with st.spinner("Generating ideas and researching..."):
|
| 153 |
+
# ideas = generate_startup_ideas(user_prompt)
|
| 154 |
+
# if not ideas:
|
| 155 |
+
# st.error("No startup ideas generated. Check API keys or try again.")
|
| 156 |
+
# else:
|
| 157 |
+
# st.subheader("π‘ Startup Ideas")
|
| 158 |
+
# for idea in ideas:
|
| 159 |
+
# st.markdown(f"- {idea}")
|
| 160 |
+
|
| 161 |
+
# st.subheader("π Market Research")
|
| 162 |
+
# for idea in ideas:
|
| 163 |
+
# title = idea.split(":")[0].strip()
|
| 164 |
+
# st.markdown(f"**π {title}**")
|
| 165 |
+
# results = market_research(title)
|
| 166 |
+
# for r in results:
|
| 167 |
+
# st.markdown(f"- {r}")
|