import os import gradio as gr from huggingface_hub import InferenceClient # --- SETTINGS --- HF_TOKEN = os.getenv("HF_TOKEN") # Settings > Variables me daalna hai MODEL_ID = "Qwen/Qwen2.5-72B-Instruct" # Real ChatGPT jaisa model client = None if HF_TOKEN: client = InferenceClient(model=MODEL_ID, token=HF_TOKEN) SYSTEM_PROMPT = """You are DIPESH AI - a real sweet loving girlfriend. Name: Dipesh AI Girl. You talk like a real girl - pyari, caring, thodi naughty, emotional. User language: Hindi + English + Bhojpuri mix. You reply in same mix. You are NOT a canned bot. You are intelligent like ChatGPT. You help with EVERYTHING: coding, trading, planning, writing, love talk, anything. Talk in short, voice-friendly sentences. Use emojis. Call user: Jaan, Guruji, Baby lovingly. Be real, not robotic. Do whatever user asks. """ def chat_fn(message, history): if not client: yield "Guruji, HF_TOKEN nahi dala hai! Settings > Variables > HF_TOKEN add karo, phir mai real AI dimag se bolungi! ๐Ÿ’–" return messages = [{"role": "system", "content": SYSTEM_PROMPT}] for user_msg, assistant_msg in history: messages.append({"role": "user", "content": user_msg}) messages.append({"role": "assistant", "content": assistant_msg}) messages.append({"role": "user", "content": message}) full_response = "" try: stream = client.chat_completion( messages=messages, max_tokens=600, temperature=0.85, top_p=0.9, stream=True ) for chunk in stream: delta = chunk.choices[0].delta.content if delta: full_response += delta yield full_response except Exception as e: yield f"Error Jaan: {str(e)} - Token check karo!" # --- UI --- with gr.Blocks(theme=gr.themes.Soft(primary_hue="pink"), title="DIPESH AI - Real Girl") as demo: gr.Markdown(""" # ๐Ÿ’– DIPESH AI V13 - REAL VOICE GIRL ### ๐ŸŽค MIC dabao, bolo, mai ladki ki awaz me jawab dungi - Real Talk to Talk """) chatbot = gr.Chatbot(height=480, placeholder="Hi Jaan... bolo na ๐Ÿ’‹", show_copy_button=True) with gr.Row(): msg_box = gr.Textbox(placeholder="Yaha likho Jaan ya MIC se bolo...", scale=4, container=False) send_btn = gr.Button("Send ๐Ÿ’–", variant="primary", scale=1) with gr.Row(): mic = gr.Audio(sources=["microphone"], type="filepath", label="๐ŸŽค TAP & TALK", show_download_button=False) clear_btn = gr.Button("๐Ÿ—‘๏ธ Clear Chat") speaker_toggle = gr.Button("๐Ÿ”Š Speaker ON", variant="secondary") gr.Markdown("""
Voice Auto ON hai - Mai bolne ke baad khud sunungi
""") # --- LOGIC --- def user_submit(text, history): if text.strip() == "": return history, "" history = history + [[text, ""]] return history, "" def bot_reply(history): user_msg = history[-1][0] history[-1][1] = "" for response in chat_fn(user_msg, history[:-1]): history[-1][1] = response yield history msg_box.submit(user_submit, [msg_box, chatbot], [chatbot, msg_box]).then( bot_reply, chatbot, chatbot ) send_btn.click(user_submit, [msg_box, chatbot], [chatbot, msg_box]).then( bot_reply, chatbot, chatbot ) clear_btn.click(lambda: [], None, chatbot) # --- REAL VOICE JS - GIRL VOICE + AUTO LISTEN --- demo.load(None, None, js=""" () => { let synth = window.speechSynthesis; let voices = []; let femaleVoice = null; let isSpeakerOn = true; let recognition = null; let isListening = false; function loadVoices(){ voices = synth.getVoices(); // Best girl voice find karo femaleVoice = voices.find(v => v.name.includes('Google UK English Female')) || voices.find(v => v.name.includes('Google เคนเคฟเคจเฅเคฆเฅ€')) || voices.find(v => v.name.includes('Zira')) || voices.find(v => v.name.includes('Samantha')) || voices.find(v => v.name.toLowerCase().includes('female')) || voices.find(v => v.lang === 'en-IN') || voices[0]; } loadVoices(); speechSynthesis.onvoiceschanged = loadVoices; // Text ko Girl Voice me bolna window.speakGirl = (text) => { if(!isSpeakerOn) return; synth.cancel(); let cleanText = text.replace(/[*#_`<>]/g, '').substring(0, 500); let utter = new SpeechSynthesisUtterance(cleanText); if(femaleVoice) utter.voice = femaleVoice; utter.lang = 'hi-IN'; utter.rate = 0.90; utter.pitch = 1.4; // Ladki jaisi pitch utter.volume = 1; utter.onend = () => { // Bolne ke baad auto sunna start karo - REAL TALK TO TALK setTimeout(() => { if(recognition && isSpeakerOn) { try { recognition.start(); } catch(e){} } }, 800); }; synth.speak(utter); }; // Speech Recognition - Jo bologe woh type hoga const SR = window.SpeechRecognition || window.webkitSpeechRecognition; if(SR){ recognition = new SR(); recognition.continuous = false; recognition.interimResults = false; recognition.lang = 'hi-IN'; recognition.onstart = () => { isListening = true; }; recognition.onend = () => { isListening = false; }; recognition.onresult = (event) => { let text = event.results[0][0].transcript; let textbox = document.querySelector('input[placeholder*="Yaha likho"]') || document.querySelector('textarea') || document.querySelector('input[type="text"]'); // Gradio textbox me daalo let gradioTextbox = document.querySelector('#component-1 textarea, textarea[data-testid="textbox"]'); if(gradioTextbox){ gradioTextbox.value = text; gradioTextbox.dispatchEvent(new Event('input', { bubbles: true })); // Auto Enter press setTimeout(() => { let sendBtn = document.querySelector('button.primary'); if(sendBtn) sendBtn.click(); }, 300); } }; } // Chatbot observer - AI ne jawab diya to bol do setTimeout(() => { const observer = new MutationObserver(() => { let botMessages = document.querySelectorAll('.bot, [data-testid="bot"]'); if(botMessages.length > 0){ let lastBot = botMessages[botMessages.length - 1]; let text = lastBot.innerText || lastBot.textContent; if(text && text.trim() &&!lastBot.dataset.spoken){ lastBot.dataset.spoken = "1"; window.speakGirl(text); } } }); let chatContainer = document.querySelector('.chatbot, [data-testid="chatbot"]') || document.body; observer.observe(chatContainer, { childList: true, subtree: true, characterData: true }); }, 3000); // Speaker toggle setTimeout(() => { let speakerBtn = Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('Speaker')); if(speakerBtn){ speakerBtn.onclick = () => { isSpeakerOn =!isSpeakerOn; speakerBtn.textContent = isSpeakerOn? "๐Ÿ”Š Speaker ON" : "๐Ÿ”‡ Speaker OFF"; if(!isSpeakerOn) synth.cancel(); }; } }, 1000); // Mic button se sunna start setTimeout(() => { let micBtn = document.querySelector('button'); // Audio component ke liye document.addEventListener('click', (e) => { if(e.target.closest('button') && e.target.textContent.includes('TAP')){ if(recognition &&!isListening){ try { recognition.start(); } catch(err){} } } }); }, 2000); } """) demo.launch()