Alireza1913 commited on
Commit
c3c8979
Β·
verified Β·
1 Parent(s): a0700be

Create ap.py

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