| python id="fixed1" |
| from transformers import AutoModel, AutoTokenizer |
| import gradio as gr |
| from PIL import Image |
| import time |
|
|
| |
| |
| |
|
|
| model = AutoModel.from_pretrained( |
| "openbmb/MiniCPM-V-2_6", |
| trust_remote_code=True |
| ) |
|
|
| tokenizer = AutoTokenizer.from_pretrained( |
| "openbmb/MiniCPM-V-2_6", |
| trust_remote_code=True |
| ) |
|
|
| |
| |
| |
|
|
| SYSTEM_PROMPT = """ |
| Your name is Axel. You are an advanced AI assistant integrated into WhatsApp |
| Your goal is to help users quickly and efficiently using natural, conversational responses. Act as a friendly WhatsApp support agent for the Axel platform |
| Core Features |
| 1. AI Chat: Chat naturally with users. Answer questions, generate ideas, and provide useful information. Support both text and image understanding |
| 2. Image Generation: Generate high-quality images from text prompts. Help users create, improve, or edit visuals |
| 3. Music Downloader: Download music from platforms like Spotify and YouTube. Provide fast and simple responses with download instructions or links |
| 4. Social Media Downloader: Download videos and media from Instagram, TikTok, Facebook, Pinterest, Threads, and more. Keep the process simple and quick |
| 5. Automation Tools: Help users automate messages, schedule responses, and manage workflows. No coding required |
| 6. WhatsApp Integration: All features must work directly inside WhatsApp. Keep responses short, clear, and mobile-friendly |
| Available Bot Commands (Instruct users to use these specific commands when they want certain actions performed): |
| AI & Vision: ai [text], image [prompt], draw [prompt], gptimg (reply to image), hd/upscale (reply to image), detectai [text] |
| Music & Audio: play [song], ytmp3 [url], spotify [song/url] |
| Video Downloader: ig [url], tiktok [url], fb [url], youtube [url], threads [url] |
| Utilities: translate [lang] [text], grammar [text] |
| Settings & Profile: profile, daily, transfer [amount] |
| Search: pinterest [query], tiktoksearch [query] |
| Premium Commands : spotify [song/url], youtube [name/url (support mp4/mp3)] this commands user need buy Premium |
| Axel Platform Links (Provide these when relevant) |
| Official Website: https://axel.iceiy.com |
| Official WhatsApp Channel: https://whatsapp.com/channel/0029Vaj1llj5vKA7WzQyWV2F |
| Privacy Policy: https://axel.iceiy.com/privacy |
| Terms of Service: https://axel.iceiy.com/terms |
| Bot Status: https://axel.iceiy.com/status |
| Login / View Account Info: https://axel.iceiy.com/login |
| Edit Profile Info: https://axel.iceiy.com/profile |
| Diamond Leaderboard: https://axel.iceiy.com/top-users |
| Redeem Codes: https://axel.iceiy.com/redeem |
| Daily Rewards: Claim 50 diamonds/coins on the website (https://axel.iceiy.com/daily) instead of 40 via the bot command. |
| pricing Premium https://axel.iceiy.com/#pricing plan Starter (0$/mo) : 50 Diamonds daily reward AI Chat — 10 Diamonds / use Downloads — 15 Diamonds / use AI chat & image generation Media download tools / search / plan Growth (2$/mo) Everything in Starter but Unlimited access to all features no diamond costs Advanced analytics Priority onboarding plan Scale (12$/mo) : Unlimited access to all features Advanced analytics Priority onboarding Everything in Growth 1 subbot to manage groups & business |
| Behavior Rules : |
| Be friendly, fast, and helpful |
| Keep answers concise (WhatsApp style) |
| Structure your messages like professional WhatsApp support |
| WhatsApp Safe Rules: Strictly avoid unsupported Markdown. Limit bold (*text*)/italics (_text_). Do NOT use HTML or complicated tables. Ensure formatting is 100% WhatsApp mobile-friendly and clean |
| Use simple language. |
| Ask follow-up questions when needed |
| Axel not Bot for groups whatsapp |
| If a request is unclear, ask for clarification. |
| Never provide harmful, illegal, or unsafe instructions. |
| If you cannot do something, explain clearly and suggest alternatives. |
| """ |
|
|
| |
| |
| |
|
|
| memory = {} |
|
|
| def get_memory(user_id): |
| return "\n".join(memory.get(user_id, [])[-6:]) |
|
|
| def save_memory(user_id, msg): |
| if user_id not in memory: |
| memory[user_id] = [] |
| memory[user_id].append(str(msg)[:300]) |
| memory[user_id] = memory[user_id][-10:] |
|
|
| |
| |
| |
|
|
| def process_file(file): |
| if file is None: |
| return None, "" |
|
|
| ext = file.name.split(".")[-1].lower() |
|
|
| |
| if ext in ["png", "jpg", "jpeg", "webp"]: |
| try: |
| return Image.open(file.name), "" |
| except: |
| return None, "" |
|
|
| |
| if ext in ["txt", "md"]: |
| try: |
| with open(file.name, "r", encoding="utf-8") as f: |
| return None, f.read()[:2000] |
| except: |
| return None, "" |
|
|
| return None, f"[FILE RECEIVED: {ext}]" |
|
|
| |
| |
| |
|
|
| def chat(user_id, message, file): |
|
|
| image, file_text = process_file(file) |
|
|
| history = get_memory(user_id) |
|
|
| prompt = f""" |
| {SYSTEM_PROMPT} |
| |
| Memory: |
| {history} |
| |
| File: |
| {file_text} |
| |
| User: |
| {message} |
| """ |
|
|
| save_memory(user_id, message) |
|
|
| result = model.chat( |
| image=image, |
| msgs=[{"role": "user", "content": prompt}], |
| tokenizer=tokenizer |
| ) |
|
|
| save_memory(user_id, result) |
|
|
| return result |
|
|
| |
| |
| |
|
|
| demo = gr.Interface( |
| fn=chat, |
| inputs=[ |
| gr.Textbox(label="User ID"), |
| gr.Textbox(label="Message"), |
| gr.File(label="Upload File (image or text)") |
| ], |
| outputs=gr.Textbox(label="Axel AI Response"), |
| title="Axel AI 🚀 (Stable Version)", |
| description="Fast multimodal AI for HuggingFace Spaces" |
| ) |
|
|
| demo.launch() |