| import gradio as gr |
| from huggingface_hub import InferenceClient |
| import os |
| import json |
| import requests |
| from fastapi import FastAPI, Request |
| from fastapi.responses import JSONResponse |
| from fastapi.staticfiles import StaticFiles |
|
|
| |
| client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct", token=os.getenv("HF_TOKEN")) |
|
|
| SPECIAL_USERS = {"nastlach", "spikelatour"} |
| paid_users = {} |
| user_usage = {} |
|
|
| LIMIT_FREE = 3 |
| PRICE_PRO = "29.00" |
| CURRENCY = "EUR" |
|
|
| |
| app = FastAPI() |
|
|
| |
| try: |
| os.makedirs("static", exist_ok=True) |
| except: |
| pass |
|
|
| |
| @app.get("/manifest.json") |
| async def get_manifest(): |
| return { |
| "name": "AI Money Machine PRO", |
| "short_name": "AI Money", |
| "description": "IA Business - Dropshipping, OnlyFans, Crypto, Dubaï", |
| "start_url": "/", |
| "display": "standalone", |
| "background_color": "#1a1a2e", |
| "theme_color": "#00ff9d", |
| "icons": [ |
| {"src": "/static/icon-192.png", "sizes": "192x192", "type": "image/png"}, |
| {"src": "/static/icon-512.png", "sizes": "512x512", "type": "image/png"} |
| ] |
| } |
|
|
| app.mount("/static", StaticFiles(directory="static"), name="static") |
|
|
| |
| @app.post("/webhook") |
| async def paypal_webhook(request: Request): |
| try: |
| body = await request.json() |
| event_type = body.get("event_type") |
| if event_type in ["CHECKOUT.ORDER.APPROVED", "PAYMENT.CAPTURE.COMPLETED"]: |
| resource = body.get("resource", {}) |
| custom_id = resource.get("purchase_units", [{}])[0].get("custom_id") |
| if custom_id: |
| user_key = str(custom_id).strip().lower() |
| paid_users[user_key] = True |
| |
| with open("paid_users.json", "w", encoding="utf-8") as f: |
| json.dump(paid_users, f) |
| except: |
| pass |
| return JSONResponse({"status": "success"}) |
|
|
| |
| def ask_ai(prompt, stream=False): |
| try: |
| messages = [ |
| {"role": "system", "content": "Tu es une IA experte en business en ligne. Réponds en Français de manière structurée et motivante."}, |
| {"role": "user", "content": prompt} |
| ] |
| output = client.chat_completion( |
| messages=messages, |
| max_tokens=1300, |
| temperature=0.75, |
| stream=stream |
| ) |
| if stream: |
| for chunk in output: |
| if chunk.choices and chunk.choices[0].delta and chunk.choices[0].delta.content: |
| yield chunk.choices[0].delta.content |
| return |
| return output.choices[0].message.content |
| except Exception as e: |
| return f"Erreur technique : {str(e)}" |
|
|
| def valider_session(p): |
| if not p or len(p.strip()) < 2: |
| return gr.update(), gr.update(), gr.update(visible=False), "⚠️ Pseudo trop court (min. 2 caractères)." |
| return gr.update(interactive=False), gr.update(visible=False), gr.update(visible=True), f"✅ Pseudo '{p}' enregistré." |
|
|
| def generate_business_plan(service, details, user_id): |
| if not user_id or user_id.strip() == "": |
| yield "❌ Valide ton pseudo d’abord." |
| return |
|
|
| original_id = user_id.strip() |
| user_key = original_id.lower() |
| is_vip = user_key in SPECIAL_USERS |
| is_pro = user_key in paid_users |
| unlimited = is_vip or is_pro |
| count = user_usage.get(user_key, 0) |
|
|
| PREMIUM_SERVICES = {"💰 Conseils Bitcoin", "🪙 Management de Coins créés en d’autres", |
| "📱 Management OnlyFans", "🐦 Management X (Twitter)", |
| "🏙️ Stratégies Dubaï High-Ticket"} |
|
|
| if service in PREMIUM_SERVICES and not unlimited: |
| yield "❌ Ce service premium est réservé aux PRO ou VIP (nastlach / spikelatour)." |
| return |
|
|
| if not unlimited and count >= LIMIT_FREE: |
| yield """❌ **LIMITE ATTEINTE !**\n\n**PASSE À LA VERSION PRO POUR UN ACCÈS ILLIMITÉ**""" |
| return |
|
|
| |
| if is_vip: |
| thinking = "🤖 **L'IA réfléchit...**\n\n✅ **ACCÈS VIP TOTAL** → Tout est gratuit et illimité" |
| elif is_pro: |
| thinking = "🤖 **L'IA réfléchit...**\n\n✅ **PRO ACTIVÉ** → Accès illimité" |
| else: |
| thinking = f"🤖 **L'IA réfléchit...**\n\n**PASSE À LA VERSION PRO POUR PLUS DE RAPIDITÉ**\n📊 Essais restants : {LIMIT_FREE - count}" |
|
|
| yield thinking |
|
|
| |
| base_prompts = { |
| "💡 Produit gagnant": "Trouve un produit dropshipping gagnant avec analyse.", |
| "🔥 Script TikTok": "Ecris un script TikTok viral avec accroche.", |
| "🛒 Boutique": "Donne 3 étapes clés pour lancer une boutique.", |
| "📈 Scaling": "Explique comment passer de 100€ à 1000€ de profit.", |
| "✍️ Question Libre": "Réponds à cette question business :", |
| "💰 Conseils Bitcoin": "Expert crypto. Conseils complets sur Bitcoin.", |
| "🪙 Management de Coins créés en d’autres": "Expert en management de coins et cryptos.", |
| "📱 Management OnlyFans": "Expert OnlyFans : croissance, contenu et monétisation.", |
| "🐦 Management X (Twitter)": "Expert Twitter/X : croissance et monétisation.", |
| "🏙️ Stratégies Dubaï High-Ticket": "Expert ventes high-ticket style Dubaï." |
| } |
|
|
| prompt_final = base_prompts.get(service, "") + f" Détails : {details}" |
|
|
| ai_response = "" |
| for chunk in ask_ai(prompt_final, stream=True): |
| ai_response += chunk |
| yield f"{thinking}\n\n{ai_response}" |
|
|
| if not unlimited: |
| user_usage[user_key] = count + 1 |
|
|
| remaining = "✅ **ACCÈS ILLIMITÉ TOTAL** 🎉" if unlimited else f"📊 Essais restants : {LIMIT_FREE - user_usage[user_key]}" |
| yield f"{ai_response}\n\n---\n{remaining}" |
|
|
| |
| with gr.Blocks( |
| theme=gr.themes.Soft(), |
| title="AI Money Machine PRO", |
| head=""" |
| <link rel="manifest" href="/manifest.json"> |
| <meta name="theme-color" content="#00ff9d"> |
| """ |
| ) as demo: |
|
|
| gr.Markdown("# 💸 AI MONEY MACHINE PRO") |
| gr.Markdown("ℹ️ Rafraîchis la page (F5) pour changer de pseudo") |
|
|
| with gr.Row(): |
| pseudo = gr.Textbox(label="👤 Ton Pseudo", placeholder="Ex: nastlach ou spikelatour", scale=3) |
| btn_valider = gr.Button("✅ Valider", variant="primary", scale=1) |
|
|
| with gr.Column(visible=False) as business_section: |
| gr.Markdown("---") |
| btn_pay = gr.Button("💎 Payer 29€ PayPal → PRO Illimité", variant="stop", size="large") |
| payment_status = gr.Markdown("") |
|
|
| choix = gr.Dropdown( |
| choices=["💡 Produit gagnant", "🔥 Script TikTok", "🛒 Boutique", "📈 Scaling", "✍️ Question Libre", |
| "💰 Conseils Bitcoin", "🪙 Management de Coins créés en d’autres", |
| "📱 Management OnlyFans", "🐦 Management X (Twitter)", |
| "🏙️ Stratégies Dubaï High-Ticket"], |
| label="Service", |
| value="💡 Produit gagnant" |
| ) |
| details = gr.Textbox(label="🎯 Détails spécifiques", placeholder="Niche, budget, objectifs...", lines=3) |
| btn_go = gr.Button("🚀 GÉNÉRER MON PLAN", variant="primary") |
|
|
| output_text = gr.Markdown(label="📋 Résultat") |
|
|
| |
| btn_valider.click(valider_session, inputs=[pseudo], outputs=[pseudo, btn_valider, business_section, output_text]) |
| btn_go.click(generate_business_plan, inputs=[choix, details, pseudo], outputs=output_text) |
| |
|
|
| |
| app = gr.mount_gradio_app(app, demo, path="/") |