Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,11 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Token'ı al
|
| 6 |
token = os.getenv("HF_TOKEN")
|
| 7 |
client = InferenceClient(token=token)
|
| 8 |
|
| 9 |
def chat_fn(message, history):
|
| 10 |
try:
|
| 11 |
-
# Gemma-2-9b, yeni sistemde en kararlı 'conversational' modeldir
|
| 12 |
response = ""
|
| 13 |
for msg in client.chat_completion(
|
| 14 |
model="google/gemma-2-9b-it",
|
|
@@ -25,39 +23,29 @@ def chat_fn(message, history):
|
|
| 25 |
yield f"Hata: {str(e)}"
|
| 26 |
|
| 27 |
def image_fn(prompt):
|
| 28 |
-
if not prompt:
|
| 29 |
-
return None
|
| 30 |
-
|
| 31 |
-
# 1. Deneme: En hızlı model (SDXL Turbo)
|
| 32 |
try:
|
| 33 |
-
|
| 34 |
-
return
|
| 35 |
-
except
|
| 36 |
-
print(f"SDXL Turbo Hatası: {e}. Yedek modele geçiliyor...")
|
| 37 |
-
|
| 38 |
-
# 2. Deneme: En kararlı yedek model (Stable Diffusion v1.5)
|
| 39 |
try:
|
| 40 |
-
|
| 41 |
-
return
|
| 42 |
-
except
|
| 43 |
-
print(f"Yedek Model Hatası: {e2}")
|
| 44 |
return None
|
| 45 |
|
| 46 |
-
# Arayüz
|
| 47 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
| 48 |
gr.Markdown("<h1 style='text-align: center;'>🚀 Maind AI Studio</h1>")
|
| 49 |
-
|
| 50 |
with gr.Tabs():
|
| 51 |
with gr.TabItem("💬 Sohbet"):
|
| 52 |
gr.ChatInterface(fn=chat_fn)
|
| 53 |
-
|
| 54 |
with gr.TabItem("🎨 Görsel"):
|
| 55 |
with gr.Row():
|
| 56 |
with gr.Column():
|
| 57 |
-
inp = gr.Textbox(label="Görsel Tarifi (İngilizce)")
|
| 58 |
-
|
| 59 |
with gr.Column():
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
demo.queue().launch()
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
token = os.getenv("HF_TOKEN")
|
| 6 |
client = InferenceClient(token=token)
|
| 7 |
|
| 8 |
def chat_fn(message, history):
|
| 9 |
try:
|
|
|
|
| 10 |
response = ""
|
| 11 |
for msg in client.chat_completion(
|
| 12 |
model="google/gemma-2-9b-it",
|
|
|
|
| 23 |
yield f"Hata: {str(e)}"
|
| 24 |
|
| 25 |
def image_fn(prompt):
|
| 26 |
+
if not prompt: return None
|
|
|
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
+
# Ana deneme
|
| 29 |
+
return client.text_to_image(prompt, model="stabilityai/sdxl-turbo")
|
| 30 |
+
except:
|
|
|
|
|
|
|
|
|
|
| 31 |
try:
|
| 32 |
+
# Yedek deneme
|
| 33 |
+
return client.text_to_image(prompt, model="runwayml/stable-diffusion-v1-5")
|
| 34 |
+
except:
|
|
|
|
| 35 |
return None
|
| 36 |
|
|
|
|
| 37 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
| 38 |
gr.Markdown("<h1 style='text-align: center;'>🚀 Maind AI Studio</h1>")
|
|
|
|
| 39 |
with gr.Tabs():
|
| 40 |
with gr.TabItem("💬 Sohbet"):
|
| 41 |
gr.ChatInterface(fn=chat_fn)
|
|
|
|
| 42 |
with gr.TabItem("🎨 Görsel"):
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column():
|
| 45 |
+
inp = gr.Textbox(label="Görsel Tarifi (İngilizce)", placeholder="Örn: Astronaut in space, high resolution...")
|
| 46 |
+
btn = gr.Button("Görseli Oluştur", variant="primary")
|
| 47 |
with gr.Column():
|
| 48 |
+
out = gr.Image(label="Sonuç")
|
| 49 |
+
btn.click(fn=image_fn, inputs=inp, outputs=out)
|
| 50 |
|
| 51 |
demo.queue().launch()
|