Update app.py
Browse files1 unmodified line234567891011121314151617186 unmodified lines2526272829303132333435363738394041422 unmodified lines454647484950514 unmodified lines565758596061626364656667682 unmodified lines717273747576777879808182838485868788899091929394959697981 unmodified line1001011021031041051061071081091101111121131 unmodified linefrom huggingface_hub import InferenceClientimport os# APIHF_TOKEN = os.getenv("HF_TOKEN")client = InferenceClient(api_key=HF_TOKEN)# --- MODEL SİYAHISI (Ehtiyat Planları) ---# Kod bu modelləri sırayla yoxlayacaq. Biri işləməsə, o birinə keçəcək.MODELS = ["meta-llama/Meta-Llama-3.1-8B-Instruct", # 1. Plan: Meta (Əgər açılsa)"Qwen/Qwen2.5-72B-Instruct", # 2. Plan: Qwen (Çox güclü və pulsuz)"mistralai/Mistral-7B-Instruct-v0.3", # 3. Plan: Mistral (Çox sürətli)"HuggingFaceH4/zephyr-7b-beta" # 4. Plan: Zephyr (Heç vaxt dayanmır)]def exypos_logic(message, history, oauth_token: gr.OAuthToken | None):6 unmodified lineselse:text = str(message)# 3. SİSTEM TƏLİMATI (GPT-4 Personası)system_prompt = (f"Sən ExyposAI-sən. İstifadəçi: {u_name}. ""Sən ən qabaqcıl süni intellekt modelisən. ""Azərbaycan dilini mükəmməl, şeir kimi bilirsən. ""Cavabların dəqiq, məntiqli və ətraflı olsun. ""Sanki bir insan kimi səmimi danış.")messages = [{"role": "system", "content": system_prompt}]# Tarixçəfor val in history:if isinstance(val, dict):if isinstance(val.get("content"), str):2 unmodified lines# Yeni mesajmessages.append({"role": "user", "content": text if text else "."})# --- FUNKSİYA 1: ŞƏKİL YARATMA (Flux - Sabitdir) ---trigger_words = ["çək", "yarat", "draw", "generate", "təsvir et"]if text and any(w in text.lower() for w in trigger_words):yield f"🎨 {u_name}, sənin üçün xüsusi bir görüntü hazırlayıram..."4 unmodified linesyield f"⚠️ Şəkil yaranmadı: {e}"return# --- FUNKSİYA 2: SÖHBƏT (Avtomatik Keçid Sistemi) ---model_worked = False# Siyahıdakı modelləri bir-bir yoxlayırıqfor model_name in MODELS:try:# Modeli yoxlayırıqstream = client.chat_completion(model=model_name,messages=messages,2 unmodified linesstream=True)# Əgər bura qədər xəta vermədisə, cavabı yazırıqfor chunk in stream:if chunk.choices and len(chunk.choices) > 0:delta = chunk.choices[0].deltaif delta and delta.content:yield delta.contentmodel_worked = Truebreak # Əgər işlədisə, dövrü dayandırırıq (o biri modellərə ehtiyac yoxdur)except Exception as e:# Xəta versə, loga yazırıq və növbəti modelə keçirikprint(f"⚠️ {model_name} işləmədi, növbətiyə keçilir...")continueif not model_worked:yield "⚠️ Bağışla, hazırda bütün serverlər doludur. Zəhmət olmasa 1 dəqiqə sonra yenidən yaz."# --- UI (Dizayn - Tam Qara/Neon/Animasiya) ---with gr.Blocks(title="Exypos AI", theme=gr.themes.Soft(), css="style.css", fill_height=True) as demo:# Arxa Fon Animasiyasıgr.HTML("""<div class="animation-wrapper"><div class="blob blob-white"></div>1 unmodified line</div>""")# Loginwith gr.Row(elem_id="header-row"):gr.LoginButton(value="G", size="sm", elem_id="login-btn")# Başlıqgr.HTML("<div id='main-title'><h1>EXYPOS AI</h1></div>")# Chat Sahəsigr.ChatInterface(fn=exypos_logic,multimodal=True,1 unmodified line2345678910111213141516176 unmodified lines24252627282930313233343536373839402 unmodified lines434445464748494 unmodified lines5455565758596061626364652 unmodified lines68697071727374757677787980818283848586878889909192931 unmodified line95969798991001011021031041051 unmodified linefrom huggingface_hub import InferenceClientimport os# API AçarıHF_TOKEN = os.getenv("HF_TOKEN")client = InferenceClient(api_key=HF_TOKEN)# --- MODEL SİYAHISI (Stabil) ---# Qwen hal-hazırda ən etibarlı və güclü pulsuz modeldir.MODELS = ["Qwen/Qwen2.5-72B-Instruct","mistralai/Mistral-7B-Instruct-v0.3","HuggingFaceH4/zephyr-7b-beta"]def exypos_logic(message, history, oauth_token: gr.OAuthToken | None):6 unmodified lineselse:text = str(message)# 3. SİSTEM TƏLİMATIsystem_prompt = (f"Sən ExyposAI-sən. İstifadəçi adı: {u_name}. ""Sən çox ağıllı, sürətli və səmimi bir süni intellektsən. ""Azərbaycan dilində səlis danış. ""Cavabların tam və məntiqli olsun. Cümlələri yarımçıq saxlama.")messages = [{"role": "system", "content": system_prompt}]# Tarixçəni təmizləyirikfor val in history:if isinstance(val, dict):if isinstance(val.get("content"), str):2 unmodified lines# Yeni mesajmessages.append({"role": "user", "content": text if text else "."})# --- FUNKSİYA 1: ŞƏKİL YARATMA (Flux) ---trigger_words = ["çək", "yarat", "draw", "generate", "təsvir et"]if text and any(w in text.lower() for w in trigger_words):yield f"🎨 {u_name}, sənin üçün xüsusi bir görüntü hazırlayıram..."4 unmodified linesyield f"⚠️ Şəkil yaranmadı: {e}"return# --- FUNKSİYA 2: SÖHBƏT (Düzəldilmiş Hissə) ---response = "" # <--- BU DƏYİŞƏN SÖZLƏRİ TOPLAYACAQmodel_worked = Falsefor model_name in MODELS:try:stream = client.chat_completion(model=model_name,messages=messages,2 unmodified linesstream=True)for chunk in stream:if chunk.choices and len(chunk.choices) > 0:delta = chunk.choices[0].deltaif delta and delta.content:response += delta.content # <--- SÖZLƏRİ BİRLƏŞDİRİRİKyield response # <--- TAM CÜMLƏNİ GÖNDƏRİRİKmodel_worked = Truebreakexcept Exception as e:print(f"⚠️ {model_name} xəta verdi: {e}")continueif not model_worked:yield "⚠️ Bağışla, serverlərdə problem var. Bir az sonra yenidən yoxla."# --- UI (Dizayn - Olduğu Kimi) ---with gr.Blocks(title="Exypos AI", theme=gr.themes.Soft(), css="style.css", fill_height=True) as demo:gr.HTML("""<div class="animation-wrapper"><div class="blob blob-white"></div>1 unmodified line</div>""")with gr.Row(elem_id="header-row"):gr.LoginButton(value="G", size="sm", elem_id="login-btn")gr.HTML("<div id='main-title'><h1>EXYPOS AI</h1></div>")gr.ChatInterface(fn=exypos_logic,multimodal=True,
app.py+21-29