File size: 6,149 Bytes
8e22fab
1bc295d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e22fab
1bc295d
 
 
 
 
8e22fab
1bc295d
 
 
 
8e22fab
1bc295d
 
 
8e22fab
1bc295d
 
 
 
 
 
 
 
8e22fab
1bc295d
 
8e22fab
1bc295d
8e22fab
1bc295d
8e22fab
 
1bc295d
8e22fab
 
1bc295d
8e22fab
1bc295d
8e22fab
1bc295d
 
8e22fab
1bc295d
 
 
 
 
 
8e22fab
1bc295d
 
 
 
 
8e22fab
1bc295d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e22fab
1bc295d
 
8e22fab
 
1bc295d
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
python id="fixed1"
from transformers import AutoModel, AutoTokenizer
import gradio as gr
from PIL import Image
import time

# ======================================================
# MODEL
# ======================================================

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
# ======================================================

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 (SAFE)
# ======================================================

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:]

# ======================================================
# FILE HANDLER (SAFE ONLY)
# ======================================================

def process_file(file):
    if file is None:
        return None, ""

    ext = file.name.split(".")[-1].lower()

    # IMAGE ONLY (safe for MiniCPM-V)
    if ext in ["png", "jpg", "jpeg", "webp"]:
        try:
            return Image.open(file.name), ""
        except:
            return None, ""

    # TEXT FILES ONLY
    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}]"

# ======================================================
# CHAT
# ======================================================

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

# ======================================================
# UI
# ======================================================

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()