Alireza1913 commited on
Commit
b84f70e
Β·
verified Β·
1 Parent(s): a1c5010

Update app.py

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