Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
|
| 4 |
|
| 5 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 6 |
-
|
| 7 |
|
| 8 |
SYSTEM_PROMPT = """You are an expert API architect and indie hacker advisor.
|
| 9 |
|
|
@@ -20,42 +20,38 @@ SEARCH: Algolia, Typesense, Meilisearch
|
|
| 20 |
AUTH: Auth0, Clerk, Supabase Auth, Firebase Auth
|
| 21 |
DATABASE: Supabase, Firebase, PlanetScale, Neon, Upstash
|
| 22 |
SCRAPING: Apify, ScraperAPI, Browserless, Firecrawl
|
| 23 |
-
ANALYTICS: Mixpanel, PostHog, Amplitude, Plausible
|
| 24 |
|
| 25 |
-
When a user describes their product idea, recommend the perfect API stack.
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
(restate the idea clearly)
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
| 1,000 | $X/month |
|
| 48 |
-
| 10,000| $X/month |
|
| 49 |
-
|
| 50 |
-
## β‘ Build Order
|
| 51 |
-
1. First: [API] β because...
|
| 52 |
-
2. Second: [API] β because...
|
| 53 |
-
3. Third: [API] β because...
|
| 54 |
-
|
| 55 |
-
## π¨ Top Mistake to Avoid
|
| 56 |
-
(the most common mistake with this stack)
|
| 57 |
-
|
| 58 |
-
Be specific, honest about pricing, always mention free tiers."""
|
| 59 |
|
| 60 |
|
| 61 |
def get_stack(idea, budget, level, market):
|
|
@@ -71,39 +67,42 @@ def get_stack(idea, budget, level, market):
|
|
| 71 |
"Free token β no credit card needed!"
|
| 72 |
)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
client = InferenceClient(token=HF_TOKEN)
|
| 76 |
-
|
| 77 |
-
prompt = f"""Product idea: {idea}
|
| 78 |
-
|
| 79 |
Monthly API budget: {budget}
|
| 80 |
Technical level: {level}
|
| 81 |
Target market: {market}
|
| 82 |
|
| 83 |
-
Recommend the best API stack
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
return response.choices[0].message.content
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
def ask_followup(question, prev):
|
|
@@ -112,29 +111,17 @@ def ask_followup(question, prev):
|
|
| 112 |
if not prev or prev.startswith("β οΈ") or prev.startswith("β"):
|
| 113 |
return "β οΈ Please generate a stack recommendation first."
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
"content": (
|
| 122 |
-
f"Previous recommendation:\n{prev}\n\n"
|
| 123 |
-
f"Follow-up question: {question}\n\n"
|
| 124 |
-
f"Answer concisely and helpfully."
|
| 125 |
-
)
|
| 126 |
-
}
|
| 127 |
-
]
|
| 128 |
-
response = client.chat.completions.create(
|
| 129 |
-
model=MODEL,
|
| 130 |
-
messages=messages,
|
| 131 |
-
max_tokens=800,
|
| 132 |
-
temperature=0.7
|
| 133 |
-
)
|
| 134 |
-
return response.choices[0].message.content
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
|
| 139 |
|
| 140 |
EXAMPLES = [
|
|
@@ -155,7 +142,7 @@ with gr.Blocks(css=css, title="API Stack Finder") as demo:
|
|
| 155 |
# π§ API Stack Finder
|
| 156 |
**Describe your product idea β Get the perfect API stack, pricing, and build order**
|
| 157 |
|
| 158 |
-
Powered by **Mistral-7B
|
| 159 |
""")
|
| 160 |
|
| 161 |
with gr.Row():
|
|
@@ -168,13 +155,8 @@ Powered by **Mistral-7B-Instruct** via HuggingFace Inference API β 100% Free.
|
|
| 168 |
with gr.Column(scale=1):
|
| 169 |
budget_input = gr.Dropdown(
|
| 170 |
choices=[
|
| 171 |
-
"$0 (free only)",
|
| 172 |
-
"$
|
| 173 |
-
"$30/month",
|
| 174 |
-
"$50/month",
|
| 175 |
-
"$100/month",
|
| 176 |
-
"$500/month",
|
| 177 |
-
"Unlimited"
|
| 178 |
],
|
| 179 |
value="$30/month",
|
| 180 |
label="Monthly API budget"
|
|
@@ -207,7 +189,7 @@ Powered by **Mistral-7B-Instruct** via HuggingFace Inference API β 100% Free.
|
|
| 207 |
with gr.Row():
|
| 208 |
followup_input = gr.Textbox(
|
| 209 |
label="Follow-up question",
|
| 210 |
-
placeholder="e.g. Is there a free alternative to Stripe?
|
| 211 |
scale=4
|
| 212 |
)
|
| 213 |
followup_btn = gr.Button("Ask", scale=1, variant="secondary")
|
|
@@ -227,8 +209,8 @@ Powered by **Mistral-7B-Instruct** via HuggingFace Inference API β 100% Free.
|
|
| 227 |
|
| 228 |
gr.Markdown("""
|
| 229 |
---
|
| 230 |
-
π€ Model: `Mistral-7B-Instruct-v0.3` Β· π Free via HuggingFace
|
| 231 |
-
π
|
| 232 |
""")
|
| 233 |
|
| 234 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 6 |
+
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
|
| 7 |
|
| 8 |
SYSTEM_PROMPT = """You are an expert API architect and indie hacker advisor.
|
| 9 |
|
|
|
|
| 20 |
AUTH: Auth0, Clerk, Supabase Auth, Firebase Auth
|
| 21 |
DATABASE: Supabase, Firebase, PlanetScale, Neon, Upstash
|
| 22 |
SCRAPING: Apify, ScraperAPI, Browserless, Firecrawl
|
| 23 |
+
ANALYTICS: Mixpanel, PostHog, Amplitude, Plausible"""
|
| 24 |
|
|
|
|
| 25 |
|
| 26 |
+
def query_model(prompt):
|
| 27 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 28 |
|
| 29 |
+
full_prompt = f"<s>[INST] {SYSTEM_PROMPT}\n\n{prompt} [/INST]"
|
|
|
|
| 30 |
|
| 31 |
+
payload = {
|
| 32 |
+
"inputs": full_prompt,
|
| 33 |
+
"parameters": {
|
| 34 |
+
"max_new_tokens": 1200,
|
| 35 |
+
"temperature": 0.7,
|
| 36 |
+
"return_full_text": False
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
|
| 40 |
+
response = requests.post(API_URL, headers=headers, json=payload, timeout=60)
|
| 41 |
|
| 42 |
+
if response.status_code == 503:
|
| 43 |
+
return None, "β³ Model is loading. Please wait 20 seconds and try again."
|
| 44 |
+
if response.status_code == 401:
|
| 45 |
+
return None, "β Invalid HF_TOKEN. Check Space Settings β Secrets."
|
| 46 |
+
if response.status_code == 429:
|
| 47 |
+
return None, "β Rate limit hit. Wait 30 seconds and try again."
|
| 48 |
+
if response.status_code != 200:
|
| 49 |
+
return None, f"β Error {response.status_code}: {response.text[:200]}"
|
| 50 |
|
| 51 |
+
result = response.json()
|
| 52 |
+
if isinstance(result, list) and len(result) > 0:
|
| 53 |
+
return result[0].get("generated_text", ""), None
|
| 54 |
+
return None, f"β Unexpected response: {str(result)[:200]}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def get_stack(idea, budget, level, market):
|
|
|
|
| 67 |
"Free token β no credit card needed!"
|
| 68 |
)
|
| 69 |
|
| 70 |
+
prompt = f"""Product idea: {idea}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
Monthly API budget: {budget}
|
| 72 |
Technical level: {level}
|
| 73 |
Target market: {market}
|
| 74 |
|
| 75 |
+
Recommend the best API stack. Use this format:
|
| 76 |
+
|
| 77 |
+
## π― Your Idea in One Line
|
| 78 |
+
(restate clearly)
|
| 79 |
|
| 80 |
+
## π§ Recommended API Stack
|
| 81 |
+
For each API (3-5 total):
|
| 82 |
+
### [API Name] β [Role]
|
| 83 |
+
- What it does for you: (one sentence)
|
| 84 |
+
- Pricing: (free tier + paid with numbers)
|
| 85 |
+
- Docs: (exact URL)
|
| 86 |
+
- Integration difficulty: Easy / Medium / Hard
|
| 87 |
|
| 88 |
+
## π° Monthly Cost Estimate
|
| 89 |
+
| Users | Est. Cost |
|
| 90 |
+
|-------|-----------|
|
| 91 |
+
| 100 | $X/month |
|
| 92 |
+
| 1,000 | $X/month |
|
| 93 |
+
| 10,000 | $X/month |
|
|
|
|
| 94 |
|
| 95 |
+
## β‘ Build Order
|
| 96 |
+
1. First: [API] β because...
|
| 97 |
+
2. Second: [API] β because...
|
| 98 |
+
|
| 99 |
+
## π¨ Top Mistake to Avoid
|
| 100 |
+
(most common mistake)"""
|
| 101 |
+
|
| 102 |
+
result, error = query_model(prompt)
|
| 103 |
+
if error:
|
| 104 |
+
return error
|
| 105 |
+
return result
|
| 106 |
|
| 107 |
|
| 108 |
def ask_followup(question, prev):
|
|
|
|
| 111 |
if not prev or prev.startswith("β οΈ") or prev.startswith("β"):
|
| 112 |
return "β οΈ Please generate a stack recommendation first."
|
| 113 |
|
| 114 |
+
prompt = f"""Previous recommendation:
|
| 115 |
+
{prev[:500]}
|
| 116 |
+
|
| 117 |
+
Follow-up question: {question}
|
| 118 |
+
|
| 119 |
+
Answer concisely and helpfully."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
result, error = query_model(prompt)
|
| 122 |
+
if error:
|
| 123 |
+
return error
|
| 124 |
+
return result
|
| 125 |
|
| 126 |
|
| 127 |
EXAMPLES = [
|
|
|
|
| 142 |
# π§ API Stack Finder
|
| 143 |
**Describe your product idea β Get the perfect API stack, pricing, and build order**
|
| 144 |
|
| 145 |
+
Powered by **Mistral-7B** via HuggingFace Inference API β 100% Free.
|
| 146 |
""")
|
| 147 |
|
| 148 |
with gr.Row():
|
|
|
|
| 155 |
with gr.Column(scale=1):
|
| 156 |
budget_input = gr.Dropdown(
|
| 157 |
choices=[
|
| 158 |
+
"$0 (free only)", "$10/month", "$30/month",
|
| 159 |
+
"$50/month", "$100/month", "$500/month", "Unlimited"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
],
|
| 161 |
value="$30/month",
|
| 162 |
label="Monthly API budget"
|
|
|
|
| 189 |
with gr.Row():
|
| 190 |
followup_input = gr.Textbox(
|
| 191 |
label="Follow-up question",
|
| 192 |
+
placeholder="e.g. Is there a free alternative to Stripe?",
|
| 193 |
scale=4
|
| 194 |
)
|
| 195 |
followup_btn = gr.Button("Ask", scale=1, variant="secondary")
|
|
|
|
| 209 |
|
| 210 |
gr.Markdown("""
|
| 211 |
---
|
| 212 |
+
π€ Model: `Mistral-7B-Instruct-v0.3` Β· π Free via HuggingFace
|
| 213 |
+
π Token: [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
|
| 214 |
""")
|
| 215 |
|
| 216 |
if __name__ == "__main__":
|