Alireza1913 commited on
Commit
f9c37d9
·
verified ·
1 Parent(s): 5f1b2d7

Delete ap.py

Browse files

import gradio as gr
import os
from anthropic import Anthropic

client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY", ""))

API_KNOWLEDGE_BASE = """
You are an expert API architect and indie hacker advisor. You know every major API deeply:

PAYMENT: Stripe, Paddle, LemonSqueezy, PayPal, Razorpay
AI/ML: OpenAI, Anthropic Claude, Replicate, HuggingFace Inference, AssemblyAI, ElevenLabs, Stability AI
COMMUNICATION: Twilio (SMS/Voice), SendGrid (email), Resend, Mailgun, Vonage, WhatsApp Business
DATA/ENRICHMENT: Clearbit, Apollo.io, Hunter.io, Proxycurl, PeopleDataLabs
MAPS/LOCATION: Google Maps, Mapbox, HERE, OpenStreetMap/Nominatim
MEDIA: Cloudinary, Mux (video), Imgix, Transloadit
FINANCE/MARKET DATA: Alpha Vantage, Polygon.io, CoinGecko, Plaid, Finnhub
SEARCH: Algolia, Typesense, Elasticsearch, Meilisearch
AUTH: Auth0, Clerk, Supabase Auth, Firebase Auth
DATABASE/BACKEND: Supabase, Firebase, PlanetScale, Neon, Upstash
SCRAPING/CRAWLING: Apify, ScraperAPI, Browserless, Firecrawl
SOCIAL: Twitter/X API, Reddit API, LinkedIn API, Instagram Graph API
PRODUCTIVITY: Notion API, Airtable, Google Workspace, Microsoft Graph
E-COMMERCE: Shopify, WooCommerce, Printful (print-on-demand)
ANALYTICS: Mixpanel, PostHog, Amplitude, Plausible
"""

SYSTEM_PROMPT = API_KNOWLEDGE_BASE + """

When a user describes their product idea, you will recommend the perfect API stack.

Your response MUST follow this exact format:

## 🎯 Your Idea in One Line
(restate the idea clearly and concisely)

## 🔧 Recommended API Stack

For each API (recommend 3-5 total), use this format:

### [API Name] — [Role in the product]
- **What it does for you:** (one sentence)
- **Pricing:** (free tier + paid tier, be specific)
- **Docs:** (exact URL)
- **Why not alternatives:** (one sentence)
- **Integration difficulty:** Easy / Medium / Hard

## 💰 Total Monthly API Cost Estimate
(breakdown for 100 users / 1000 users / 10,000 users)

## ⚡ Build Order
(which API to integrate first, second, third — and why)

## 🚨 One Thing to Watch Out For
(the most common mistake with this stack)

Be specific, honest about pricing, and always mention free tiers.
"""

def get_stack_recommendation(idea, budget, technical_level, target_market):
if not idea.strip():
return "Please describe your product idea first."

if not client.api_key:
return "⚠️ ANTHROPIC_API_KEY is not set. Add it in Space Settings → Secrets."

user_message = f"""
My product idea: {idea}

My monthly API budget: {budget}
My technical level: {technical_level}
Target market: {target_market}

Please recommend the best API stack for this.
"""

try:
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1500,
system=SYSTEM_PROMPT,
messages=[{"role": "user", "content": user_message}]
)
return response.content[0].text
except Exception as e:
return f"❌ Error: {str(e)}"

def ask_followup(question, previous_recommendation):
if not question.strip():
return ""
if not previous_recommendation or previous_recommendation.startswith("Please") or previous_recommendation.startswith("⚠️"):
return "Please generate a stack recommendation first."

try:
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=800,
system=SYSTEM_PROMPT,
messages=[
{
"role": "user",
"content": f"I got this API stack recommendation:\n\n{previous_recommendation}\n\nMy follow-up question: {question}"
}
]
)
return response.content[0].text
except Exception as e:
return f"❌ Error: {str(e)}"

EXAMPLES = [
["A Notion-like note taking app with AI summarization", "$50/month", "Intermediate", "Students and researchers"],
["An SMS marketing platform for small restaurants", "$30/month", "Beginner", "Local restaurant owners"],
["A job board that auto-matches candidates with AI", "$100/month", "Advanced", "Tech recruiters"],
["A podcast transcription and highlight tool", "$20/month", "Beginner", "Podcasters"],
["A crypto portfolio tracker with price alerts", "$0 (free only)", "Intermediate", "Retail crypto investors"],
]

css = """
.gradio-container { max-width: 900px !important; margin: auto; }
footer { display: none !important; }
"""

with gr.Blocks(css=css, title="API Stack Finder") as demo:
gr.Markdown("""
# 🔧 API Stack Finder
**Describe your product idea → Get the perfect API stack, pricing breakdown, and build order**

Powered by Claude (Anthropic) — No more guessing which APIs to use.
""")

with gr.Row():
with gr.Column(scale=3):
idea_input = gr.Textbox(
label="Describe your product idea",
placeholder="e.g. A platform where freelancers can sell their services and get paid instantly via Stripe...",
lines=4
)
with gr.Column(scale=1):
budget_input = gr.Dropdown(
choices=["$0 (free only)", "$10/month", "$30/month", "$50/month", "$100/month", "$500/month", "Unlimited"],
value="$30/month",
label="Monthly API budget"
)
level_input = gr.Dropdown(
choices=["Beginner", "Intermediate", "Advanced"],
value="Intermediate",
label="Your technical level"
)
market_input = gr.Textbox(
label="Target market",
placeholder="e.g. Small business owners in Europe",
value="General consumers"
)

gr.Markdown("**Try an example:**")
with gr.Row():
for ex in EXAMPLES:
gr.Button(ex[0][:35] + "...", size="sm").click(
lambda e=ex: (e[0], e[1], e[2], e[3]),
outputs=[idea_input, budget_input, level_input, market_input]
)

submit_btn = gr.Button("🔍 Find My API Stack", variant="primary", size="lg")

recommendation_output = gr.Markdown(
value="*Your API stack recommendation will appear here...*",
label="Recommended Stack"
)

gr.Markdown("---")
gr.Markdown("### 💬 Ask a follow-up question")
with gr.Row():
followup_input = gr.Textbox(
label="Follow-up",
placeholder="e.g. Is there a cheaper alternative to Twilio? / How do I handle auth without Auth0?",
scale=4
)
followup_btn = gr.Button("Ask", scale=1, variant="secondary")

followup_output = gr.Markdown()

submit_btn.click(
get_stack_recommendation,
inputs=[idea_input, budget_input, level_input, market_input],
outputs=recommendation_output
)

followup_btn.click(
ask_followup,
inputs=[followup_input, recommendation_output],
outputs=followup_output
)

gr.Markdown("""
---
Built with [Gradio](https://gradio.app) + [Claude](https://anthropic.com) ·
[View on HuggingFace](https://huggingface.co/spaces/Alireza1913/Monetizable_API_Finder)
""")

if __name__ == "__main__":
demo.launch()

Files changed (1) hide show
  1. ap.py +0 -200
ap.py DELETED
@@ -1,200 +0,0 @@
1
- import gradio as gr
2
- import os
3
- from anthropic import Anthropic
4
-
5
- client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY", ""))
6
-
7
- API_KNOWLEDGE_BASE = """
8
- You are an expert API architect and indie hacker advisor. You know every major API deeply:
9
-
10
- PAYMENT: Stripe, Paddle, LemonSqueezy, PayPal, Razorpay
11
- AI/ML: OpenAI, Anthropic Claude, Replicate, HuggingFace Inference, AssemblyAI, ElevenLabs, Stability AI
12
- COMMUNICATION: Twilio (SMS/Voice), SendGrid (email), Resend, Mailgun, Vonage, WhatsApp Business
13
- DATA/ENRICHMENT: Clearbit, Apollo.io, Hunter.io, Proxycurl, PeopleDataLabs
14
- MAPS/LOCATION: Google Maps, Mapbox, HERE, OpenStreetMap/Nominatim
15
- MEDIA: Cloudinary, Mux (video), Imgix, Transloadit
16
- FINANCE/MARKET DATA: Alpha Vantage, Polygon.io, CoinGecko, Plaid, Finnhub
17
- SEARCH: Algolia, Typesense, Elasticsearch, Meilisearch
18
- AUTH: Auth0, Clerk, Supabase Auth, Firebase Auth
19
- DATABASE/BACKEND: Supabase, Firebase, PlanetScale, Neon, Upstash
20
- SCRAPING/CRAWLING: Apify, ScraperAPI, Browserless, Firecrawl
21
- SOCIAL: Twitter/X API, Reddit API, LinkedIn API, Instagram Graph API
22
- PRODUCTIVITY: Notion API, Airtable, Google Workspace, Microsoft Graph
23
- E-COMMERCE: Shopify, WooCommerce, Printful (print-on-demand)
24
- ANALYTICS: Mixpanel, PostHog, Amplitude, Plausible
25
- """
26
-
27
- SYSTEM_PROMPT = API_KNOWLEDGE_BASE + """
28
-
29
- When a user describes their product idea, you will recommend the perfect API stack.
30
-
31
- Your response MUST follow this exact format:
32
-
33
- ## 🎯 Your Idea in One Line
34
- (restate the idea clearly and concisely)
35
-
36
- ## 🔧 Recommended API Stack
37
-
38
- For each API (recommend 3-5 total), use this format:
39
-
40
- ### [API Name] — [Role in the product]
41
- - **What it does for you:** (one sentence)
42
- - **Pricing:** (free tier + paid tier, be specific)
43
- - **Docs:** (exact URL)
44
- - **Why not alternatives:** (one sentence)
45
- - **Integration difficulty:** Easy / Medium / Hard
46
-
47
- ## 💰 Total Monthly API Cost Estimate
48
- (breakdown for 100 users / 1000 users / 10,000 users)
49
-
50
- ## ⚡ Build Order
51
- (which API to integrate first, second, third — and why)
52
-
53
- ## 🚨 One Thing to Watch Out For
54
- (the most common mistake with this stack)
55
-
56
- Be specific, honest about pricing, and always mention free tiers.
57
- """
58
-
59
- def get_stack_recommendation(idea, budget, technical_level, target_market):
60
- if not idea.strip():
61
- return "Please describe your product idea first."
62
-
63
- if not client.api_key:
64
- return "⚠️ ANTHROPIC_API_KEY is not set. Add it in Space Settings → Secrets."
65
-
66
- user_message = f"""
67
- My product idea: {idea}
68
-
69
- My monthly API budget: {budget}
70
- My technical level: {technical_level}
71
- Target market: {target_market}
72
-
73
- Please recommend the best API stack for this.
74
- """
75
-
76
- try:
77
- response = client.messages.create(
78
- model="claude-sonnet-4-6",
79
- max_tokens=1500,
80
- system=SYSTEM_PROMPT,
81
- messages=[{"role": "user", "content": user_message}]
82
- )
83
- return response.content[0].text
84
- except Exception as e:
85
- return f"❌ Error: {str(e)}"
86
-
87
- def ask_followup(question, previous_recommendation):
88
- if not question.strip():
89
- return ""
90
- if not previous_recommendation or previous_recommendation.startswith("Please") or previous_recommendation.startswith("⚠️"):
91
- return "Please generate a stack recommendation first."
92
-
93
- try:
94
- response = client.messages.create(
95
- model="claude-sonnet-4-6",
96
- max_tokens=800,
97
- system=SYSTEM_PROMPT,
98
- messages=[
99
- {
100
- "role": "user",
101
- "content": f"I got this API stack recommendation:\n\n{previous_recommendation}\n\nMy follow-up question: {question}"
102
- }
103
- ]
104
- )
105
- return response.content[0].text
106
- except Exception as e:
107
- return f"❌ Error: {str(e)}"
108
-
109
- EXAMPLES = [
110
- ["A Notion-like note taking app with AI summarization", "$50/month", "Intermediate", "Students and researchers"],
111
- ["An SMS marketing platform for small restaurants", "$30/month", "Beginner", "Local restaurant owners"],
112
- ["A job board that auto-matches candidates with AI", "$100/month", "Advanced", "Tech recruiters"],
113
- ["A podcast transcription and highlight tool", "$20/month", "Beginner", "Podcasters"],
114
- ["A crypto portfolio tracker with price alerts", "$0 (free only)", "Intermediate", "Retail crypto investors"],
115
- ]
116
-
117
- css = """
118
- .gradio-container { max-width: 900px !important; margin: auto; }
119
- footer { display: none !important; }
120
- """
121
-
122
- with gr.Blocks(css=css, title="API Stack Finder") as demo:
123
- gr.Markdown("""
124
- # 🔧 API Stack Finder
125
- **Describe your product idea → Get the perfect API stack, pricing breakdown, and build order**
126
-
127
- Powered by Claude (Anthropic) — No more guessing which APIs to use.
128
- """)
129
-
130
- with gr.Row():
131
- with gr.Column(scale=3):
132
- idea_input = gr.Textbox(
133
- label="Describe your product idea",
134
- placeholder="e.g. A platform where freelancers can sell their services and get paid instantly via Stripe...",
135
- lines=4
136
- )
137
- with gr.Column(scale=1):
138
- budget_input = gr.Dropdown(
139
- choices=["$0 (free only)", "$10/month", "$30/month", "$50/month", "$100/month", "$500/month", "Unlimited"],
140
- value="$30/month",
141
- label="Monthly API budget"
142
- )
143
- level_input = gr.Dropdown(
144
- choices=["Beginner", "Intermediate", "Advanced"],
145
- value="Intermediate",
146
- label="Your technical level"
147
- )
148
- market_input = gr.Textbox(
149
- label="Target market",
150
- placeholder="e.g. Small business owners in Europe",
151
- value="General consumers"
152
- )
153
-
154
- gr.Markdown("**Try an example:**")
155
- with gr.Row():
156
- for ex in EXAMPLES:
157
- gr.Button(ex[0][:35] + "...", size="sm").click(
158
- lambda e=ex: (e[0], e[1], e[2], e[3]),
159
- outputs=[idea_input, budget_input, level_input, market_input]
160
- )
161
-
162
- submit_btn = gr.Button("🔍 Find My API Stack", variant="primary", size="lg")
163
-
164
- recommendation_output = gr.Markdown(
165
- value="*Your API stack recommendation will appear here...*",
166
- label="Recommended Stack"
167
- )
168
-
169
- gr.Markdown("---")
170
- gr.Markdown("### 💬 Ask a follow-up question")
171
- with gr.Row():
172
- followup_input = gr.Textbox(
173
- label="Follow-up",
174
- placeholder="e.g. Is there a cheaper alternative to Twilio? / How do I handle auth without Auth0?",
175
- scale=4
176
- )
177
- followup_btn = gr.Button("Ask", scale=1, variant="secondary")
178
-
179
- followup_output = gr.Markdown()
180
-
181
- submit_btn.click(
182
- get_stack_recommendation,
183
- inputs=[idea_input, budget_input, level_input, market_input],
184
- outputs=recommendation_output
185
- )
186
-
187
- followup_btn.click(
188
- ask_followup,
189
- inputs=[followup_input, recommendation_output],
190
- outputs=followup_output
191
- )
192
-
193
- gr.Markdown("""
194
- ---
195
- Built with [Gradio](https://gradio.app) + [Claude](https://anthropic.com) ·
196
- [View on HuggingFace](https://huggingface.co/spaces/Alireza1913/Monetizable_API_Finder)
197
- """)
198
-
199
- if __name__ == "__main__":
200
- demo.launch()