Alireza1913 commited on
Commit
45baf6d
Β·
verified Β·
1 Parent(s): f9c37d9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +200 -0
app.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()