Spaces:
Paused
Paused
feat: Add Gemini 2.5 Flash Prompt Engineering and Flux support
Browse filesFiles changed (4)
- .env+2
- bot/bot.js+69-147
- package-lock.json+11
- package.json+1
1 unmodified line2341 unmodified lineMONGO_URI=mongodb+srv://ibrohm135:mansur5754@cluster0.intw8qq.mongodb.net/savdo?appName=Cluster0BOT_TOKEN=8606505490:AAETdDAWWis5jLEXEmD2k6wRRrhHGubelBIADMIN_ID=63099008801 unmodified line234561 unmodified lineMONGO_URI=mongodb+srv://ibrohm135:mansur5754@cluster0.intw8qq.mongodb.net/savdo?appName=Cluster0BOT_TOKEN=8606505490:AAETdDAWWis5jLEXEmD2k6wRRrhHGubelBIADMIN_ID=6309900880GEMINI_API_KEY=AIzaSyDtNZY4hzgbnaSD1Y1N2N94qGCJ2arKfq4
5 unmodified lines6789101119 unmodified lines313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130738 unmodified lines869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907234 unmodified lines11421143114411451146114711481 unmodified line11501151115211531154115511561 unmodified line11581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711885 unmodified linesconst dns = require('dns');const https = require('https');const http = require('http');dns.setDefaultResultOrder('ipv4first');19 unmodified lines});}// O'zbekcha => Inglizcha tarjima lug'ati (150+ so'z)const uzToEn = {// === KIYIM & MODA ==='kiyim': 'clothing apparel', 'kiyimlar': 'clothing fashion collection', 'libos': 'outfit elegant dress','manti': 'formal blazer coat overcoat', 'mantiya': 'formal blazer coat', 'palto': 'coat winter jacket','kostyum': 'formal business suit', 'koylak': 'shirt blouse', 'ko\'ylak': 'shirt blouse','shim': 'pants trousers', 'jinsi': 'jeans denim', 'futbolka': 'tshirt casual','kurtka': 'jacket outerwear', 'sviter': 'sweater knitwear', 'yubka': 'skirt','plashch': 'raincoat', 'shortik': 'shorts', 'pidjak': 'blazer jacket','galstuk': 'tie necktie', 'shapka': 'hat cap beanie', 'sharf': 'scarf','poyafzal': 'shoes footwear', 'krossovka': 'sneakers trainers', 'tufli': 'formal shoes heels','sumka': 'bag handbag purse', 'kamar': 'belt leather', 'soat': 'watch luxury wristwatch','ko\'zoynak': 'sunglasses eyewear', 'uzuk': 'ring jewelry', 'sirga': 'earrings jewelry','marjonlar': 'necklace beads', 'aksessuar': 'accessories fashion',// === ODAMLAR ==='yigit': 'young man handsome', 'qiz': 'young woman beautiful girl', 'ayol': 'woman elegant lady','erkak': 'man gentleman', 'talaba': 'student university campus', 'bolalar': 'children kids cute','oila': 'family together', 'bola': 'child kid', 'kelin': 'bride beautiful','kuyov': 'groom handsome', 'model': 'fashion model professional',// === TADBIRLAR ==='bitiruv': 'graduation ceremony celebration', 'oqshom': 'evening gala night party','bayram': 'celebration holiday festive joyful', 'toy': 'wedding ceremony luxurious','tug\'ilgan': 'birthday party celebration', 'kun': 'day','mehmon': 'guest party gathering', 'konsert': 'concert music performance','festival': 'festival carnival vibrant',// === MARKETING & SAVDO ==='chegirma': 'sale discount mega promotion', 'aksiya': 'special offer flash deal sale','chegirmalar': 'discounts promotions deals', 'yangilik': 'new arrivals fresh trending','yangi': 'new fresh latest', 'kolleksiya': 'collection exclusive', 'bepul': 'free bonus gift','cheklangan': 'limited edition exclusive', 'tez': 'fast quick express', 'buyurtma': 'order delivery','yetkazish': 'delivery shipping fast', 'foiz': 'percent off discount','super': 'super mega amazing', 'maxsus': 'special exclusive VIP','eng': 'best top number one', 'arzon': 'affordable budget cheap','sifatli': 'premium quality high-end', 'original': 'original authentic genuine','top': 'top bestseller trending', 'hit': 'bestseller popular trending',// === TEXNOLOGIYA ==='texnika': 'electronics technology gadgets', 'telefon': 'smartphone mobile phone','kompyuter': 'computer laptop desktop', 'planshet': 'tablet iPad digital','quloqchin': 'headphones earbuds audio', 'kamera': 'camera photography DSLR','televizor': 'television TV screen', 'printer': 'printer scanner office','naushnik': 'headphones wireless bluetooth', 'zaryadka': 'charger power bank','robot': 'robot technology AI smart', 'dron': 'drone aerial photography',// === RANGLAR ==='qizil': 'red crimson', 'ko\'k': 'blue navy', 'yashil': 'green emerald','sariq': 'yellow golden bright', 'oq': 'white clean pure', 'qora': 'black dark sleek','pushti': 'pink rose', 'binafsha': 'purple violet', 'to\'q': 'dark deep rich','och': 'light pastel soft', 'oltin': 'gold golden luxurious', 'kumush': 'silver metallic','rangli': 'colorful vibrant rainbow', 'rang': 'color hue tone',// === FASLLAR & OB-HAVO ==='yil': 'year annual', 'yoz': 'summer sunny warm', 'qish': 'winter cold snowy','kuz': 'autumn fall harvest', 'bahor': 'spring blossom fresh','issiq': 'hot warm tropical', 'sovuq': 'cold cool freezing','yomg\'ir': 'rain rainy', 'quyosh': 'sun sunshine bright',// === JOY & MUHIT ==='dokon': 'store shop boutique', 'savdo': 'shopping commerce business','bozor': 'market marketplace bazaar', 'uy': 'home interior house', 'hovli': 'garden yard','mebel': 'furniture interior design', 'oshxona': 'kitchen cooking culinary','yotoqxona': 'bedroom cozy interior', 'ofis': 'office workspace business','restoran': 'restaurant dining fine', 'kafe': 'cafe coffeeshop trendy','park': 'park nature outdoor', 'shahar': 'city urban modern skyline','tog\'': 'mountain landscape nature', 'dengiz': 'sea ocean beach tropical','ko\'cha': 'street urban lifestyle',// === KAYFIYAT & SIFAT ==='zamonaviy': 'modern contemporary chic', 'chiroyli': 'beautiful gorgeous stunning','hashamatli': 'luxurious opulent elegant', 'oddiy': 'simple minimalist clean','klassik': 'classic timeless elegant', 'romantik': 'romantic lovely dreamy','premium': 'premium luxury exclusive', 'professional': 'professional expert polished','sport': 'sport athletic fitness active', 'moda': 'fashion trendy stylish haute couture','ajoyib': 'amazing wonderful fantastic', 'zo\'r': 'cool awesome great','go\'zal': 'beautiful gorgeous pretty',// === HARAKATLAR ==='kiyib': 'wearing dressed in', 'turgan': 'standing posing', 'yurgan': 'walking strolling','o\'tirgan': 'sitting relaxed', 'yugurgan': 'running jogging active','ko\'rsatib': 'showing demonstrating showcasing', 'sotib': 'buying shopping purchasing',// === SOVG'A & ULOV ==='sovga': 'gift present wrapped surprise', 'mashina': 'car automobile vehicle luxury','avto': 'auto car vehicle', 'velosiped': 'bicycle cycling sport',// === GRAMMATIK SO'ZLAR ==='va': 'and', 'bilan': 'with', 'uchun': 'for', 'da': 'in at', 'ning': 'of','ga': 'to towards', 'dan': 'from', 'lar': '', 'har': 'every each','eng': 'most best top', 'juda': 'very extremely highly',// === FILTER SO'ZLAR ==='rasmini': '', 'chizib': '', 'ber': '', 'bersin': '', 'rasm': '', 'yasab': '', 'yasa': ''};function translatePrompt(uzText) {let words = uzText.toLowerCase().split(/\s+/);let translated = words.map(w => {for (const [uz, en] of Object.entries(uzToEn)) {if (w === uz || w.startsWith(uz)) return en;}return w; // Topilmasa o'zi qoladi}).filter(w => w.length > 0).join(' ');return translated + ', wide landscape banner, professional advertising photography, cinematic lighting, vivid colors, high detail, photorealistic, no text on image';}// AI Banner Shablon Promptlari738 unmodified linesconst ts1 = Date.now();const ts2 = ts1 + 12345;const encoded = encodeURIComponent(finalPrompt);const url1 = `https://image.pollinations.ai/prompt/${encoded}?width=1024&height=512&seed=${ts1}&nologo=true`;const url2 = `https://image.pollinations.ai/prompt/${encoded}?width=1024&height=512&seed=${ts2}&nologo=true`;await ctx.reply('β³ AI 2 ta variant yaratmoqda... (20-40 soniya kutib turing)');try {// Ikkalasini parallel yuklab olishconst [buffer1, buffer2] = await Promise.all([downloadImage(url1),downloadImage(url2)]);// 1-variantconst msg1 = await ctx.replyWithPhoto({ source: buffer1, filename: 'variant1.jpg' }, {caption: `π¨ *Variant 1*\nπ _"${originalPrompt}"_`,parse_mode: 'Markdown',...Markup.inlineKeyboard([[Markup.button.callback('β Shu rasmni tanlash', 'ai_pick_1')]])});// 2-variantconst msg2 = await ctx.replyWithPhoto({ source: buffer2, filename: 'variant2.jpg' }, {caption: `π¨ *Variant 2*\nπ _"${originalPrompt}"_`,parse_mode: 'Markdown',...Markup.inlineKeyboard([[Markup.button.callback('β Shu rasmni tanlash', 'ai_pick_2')]])});// FileID larni olishconst fileId1 = msg1.photo[msg1.photo.length - 1].file_id;const fileId2 = msg2.photo[msg2.photo.length - 1].file_id;appState[userId] = {step: 'ai_picking_variant',234 unmodified lines// AI Banner β Shablon bilanif (state.step === 'ai_template_prompt') {const userText = text.toLowerCase() === 'davom' ? '' : text;const finalPrompt = state.templateBase + (userText ? ', ' + translatePrompt(userText) : '') + ', wide landscape banner, professional advertising, cinematic lighting, vivid colors, photorealistic, no text on image';appState[userId] = { step: 'ai_generating', lastPrompt: text, templateBase: state.templateBase, finalPrompt };await generateAIBannerVariants(ctx, finalPrompt, text || aiTemplates[state.templateKey]?.label || 'AI Banner');return;1 unmodified line// AI Banner β Erkin yozishif (state.step === 'ai_free_prompt_input') {const finalPrompt = translatePrompt(text);appState[userId] = { step: 'ai_generating', lastPrompt: text, finalPrompt };await generateAIBannerVariants(ctx, finalPrompt, text);return;1 unmodified line// AI Banner (eski usul backup)if (state.step === 'ai_banner_prompt') {const prompt = text;appState[userId] = { step: 'ai_banner_waiting', lastPrompt: prompt };const ts = Date.now();const aiPrompt = translatePrompt(prompt);const encodedPrompt = encodeURIComponent(aiPrompt);const imgUrl = `https://image.pollinations.ai/prompt/${encodedPrompt}?width=1024&height=512&seed=${ts}&nologo=true`;ctx.reply('β³ AI rasm yaratilmoqda... (10-30 soniya kutib turing)');try {const buffer = await downloadImage(imgUrl);await ctx.replyWithPhoto({ source: buffer, filename: 'banner.jpg' }, {caption: `π¨ *AI Banner tayyor!*\n\nπ _"${prompt}"_\n\nBu rasmni banner sifatida qo'shmoqchimisiz?`,parse_mode: 'Markdown',...Markup.inlineKeyboard([[Markup.button.callback('β Tasdiqlash va qo\'shish', 'ai_save_last')],[Markup.button.callback('π Qayta yaratish', 'ai_regenerate'), Markup.button.callback('β Bekor qilish', 'action_banners')]])});appState[userId].lastImageUrl = imgUrl;} catch(e) {ctx.reply('β Rasm yaratishda xatolik: ' + e.message + '\nQayta urining.', getMainMenu());delete appState[userId];}return;}5 unmodified lines6789101112131419 unmodified lines343536373839404142434445464748495051525354555657585960738 unmodified lines799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848234 unmodified lines108310841085108610871088108910901 unmodified line109210931094109510961097109810991 unmodified line11011102110311041105110611071108110911105 unmodified linesconst dns = require('dns');const https = require('https');const http = require('http');const { GoogleGenerativeAI } = require('@google/generative-ai');const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || '');dns.setDefaultResultOrder('ipv4first');19 unmodified lines});}// AI yordamida (Gemini) promptni professional darajada kengaytirishasync function enhancePromptWithGemini(userText, templateBase = '') {if (!process.env.GEMINI_API_KEY) {return (templateBase ? templateBase + ', ' : '') + userText + ', professional advertising banner, highly detailed';}try {const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" });const prompt = `You are an expert AI image prompt engineer. The user wants to generate an e-commerce banner.Convert the following short idea (often in Uzbek) into a highly detailed, professional, comma-separated English prompt for a text-to-image AI (like Flux or Midjourney).Ensure it describes the visual elements beautifully. Include stylistic tags like: wide landscape banner, professional advertising photography, cinematic lighting, vivid colors, photorealistic, 8k resolution, highly detailed, no text on image.If a template context is provided, combine it smoothly.Template Context: ${templateBase || 'None'}User's Idea: "${userText}"Respond ONLY with the final English prompt string, and nothing else.`;const result = await model.generateContent(prompt);return result.response.text().trim();} catch (e) {console.error("Gemini error:", e);return (templateBase ? templateBase + ', ' : '') + userText + ', professional advertising banner, cinematic lighting, photorealistic';}}// AI Banner Shablon Promptlari738 unmodified linesconst ts1 = Date.now();const ts2 = ts1 + 12345;const encoded = encodeURIComponent(finalPrompt);// Hozirgi eng maxsus fotorealistik model: FLUXconst url1 = `https://image.pollinations.ai/prompt/${encoded}?width=1024&height=512&seed=${ts1}&nologo=true&model=flux`;const url2 = `https://image.pollinations.ai/prompt/${encoded}?width=1024&height=512&seed=${ts2}&nologo=true&model=flux`;await ctx.reply('β³ Gemini promptni kengaytirib, Flux 2 ta variant yaratmoqda... (Kuting, 20-40 soniya)');try {// Ikkalasini xavfsiz yuklab olish (biri xato qilsa ham ikkinchisi ishlaydi)const results = await Promise.allSettled([downloadImage(url1),downloadImage(url2)]);let msg1, msg2;let fileId1 = null, fileId2 = null;// 1-variant tekshiriladiif (results[0].status === 'fulfilled') {msg1 = await ctx.replyWithPhoto({ source: results[0].value, filename: 'variant1.jpg' }, {caption: `π¨ *Variant 1*\nπ _"${originalPrompt}"_\n\nπ€ _Gemini kuchi bilan yozildi_`,parse_mode: 'Markdown',...Markup.inlineKeyboard([[Markup.button.callback('β Shu rasmni tanlash', 'ai_pick_1')]])});fileId1 = msg1.photo[msg1.photo.length - 1].file_id;} else {await ctx.reply('β οΈ Variant 1 ni yuklab olishda serverda xatolik yuz berdi.');}// 2-variant tekshiriladiif (results[1].status === 'fulfilled') {msg2 = await ctx.replyWithPhoto({ source: results[1].value, filename: 'variant2.jpg' }, {caption: `π¨ *Variant 2*\nπ _"${originalPrompt}"_\n\nπ€ _Gemini kuchi bilan yozildi_`,parse_mode: 'Markdown',...Markup.inlineKeyboard([[Markup.button.callback('β Shu rasmni tanlash', 'ai_pick_2')]])});fileId2 = msg2.photo[msg2.photo.length - 1].file_id;} else {await ctx.reply('β οΈ Variant 2 ni yuklab olishda serverda xatolik yuz berdi.');}if (!fileId1 && !fileId2) {throw new Error("Ikkala rasm ham yuklanmadi. Iltimos, qayta urining.");}appState[userId] = {step: 'ai_picking_variant',234 unmodified lines// AI Banner β Shablon bilanif (state.step === 'ai_template_prompt') {const userText = text.toLowerCase() === 'davom' ? '' : text;await ctx.reply('π§ Gemini loyihangizni anglab, mukammal prompt tuzmoqda...');const finalPrompt = await enhancePromptWithGemini(userText, state.templateBase);appState[userId] = { step: 'ai_generating', lastPrompt: text, templateBase: state.templateBase, finalPrompt };await generateAIBannerVariants(ctx, finalPrompt, text || aiTemplates[state.templateKey]?.label || 'AI Banner');return;1 unmodified line// AI Banner β Erkin yozishif (state.step === 'ai_free_prompt_input') {await ctx.reply('π§ Gemini sizning fikringiz asosida mukammal prompt tuzmoqda...');const finalPrompt = await enhancePromptWithGemini(text);appState[userId] = { step: 'ai_generating', lastPrompt: text, finalPrompt };await generateAIBannerVariants(ctx, finalPrompt, text);return;1 unmodified line// AI Banner (eski usul backup)if (state.step === 'ai_banner_prompt') {await ctx.reply('π§ Gemini orqali prompt tayyorlanmoqda...');const finalPrompt = await enhancePromptWithGemini(text);appState[userId] = { step: 'ai_generating', lastPrompt: text, finalPrompt };await generateAIBannerVariants(ctx, finalPrompt, text);return;}
8 unmodified lines9101112131415161718192021228 unmodified lines"version": "1.0.0","license": "ISC","dependencies": {"cors": "^2.8.6","dotenv": "^17.4.1","express": "^5.2.1","mongoose": "^9.4.1","multer": "^2.1.1","telegraf": "^4.16.3"}},"node_modules/@mongodb-js/saslprep": {"version": "1.4.6","resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.6.tgz",8 unmodified lines91011121314151617181920212223242526272829303132338 unmodified lines"version": "1.0.0","license": "ISC","dependencies": {"@google/generative-ai": "^0.24.1","cors": "^2.8.6","dotenv": "^17.4.1","express": "^5.2.1","mongoose": "^9.4.1","multer": "^2.1.1","node-fetch": "^2.7.0","telegraf": "^4.16.3"}},"node_modules/@google/generative-ai": {"version": "0.24.1","resolved": "https://registry.npmjs.org/@google/generative-ai/-/generative-ai-0.24.1.tgz","integrity": "sha512-MqO+MLfM6kjxcKoy0p1wRzG3b4ZZXtPI+z2IE26UogS2Cm/XHO+7gGRBh6gcJsOiIVoH93UwKvW4HdgiOZCy9Q==","license": "Apache-2.0","engines": {"node": ">=18.0.0"}},"node_modules/@mongodb-js/saslprep": {"version": "1.4.6","resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.6.tgz",
10 unmodified lines11121314151610 unmodified lines"license": "ISC","type": "commonjs","dependencies": {"cors": "^2.8.6","dotenv": "^17.4.1","express": "^5.2.1",10 unmodified lines1112131415161710 unmodified lines"license": "ISC","type": "commonjs","dependencies": {"@google/generative-ai": "^0.24.1","cors": "^2.8.6","dotenv": "^17.4.1","express": "^5.2.1",
.env+2
bot/bot.js+69-147
package-lock.json+11
package.json+1