Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
token = os.getenv("HF_TOKEN")
|
| 6 |
client = InferenceClient(token=token)
|
| 7 |
|
|
@@ -25,27 +26,37 @@ def chat_fn(message, history):
|
|
| 25 |
def image_fn(prompt):
|
| 26 |
if not prompt: return None
|
| 27 |
try:
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
with gr.Tabs():
|
| 40 |
-
with gr.TabItem("💬 Sohbet"):
|
| 41 |
gr.ChatInterface(fn=chat_fn)
|
| 42 |
-
|
|
|
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column():
|
| 45 |
-
inp = gr.Textbox(label="Görsel Tarifi (İngilizce)", placeholder="Örn:
|
| 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()
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Token ayarı
|
| 6 |
token = os.getenv("HF_TOKEN")
|
| 7 |
client = InferenceClient(token=token)
|
| 8 |
|
|
|
|
| 26 |
def image_fn(prompt):
|
| 27 |
if not prompt: return None
|
| 28 |
try:
|
| 29 |
+
# En kararlı ve yeni model olan FLUX veya SDXL'i doğrudan API ile çağırıyoruz
|
| 30 |
+
# Bu metod 'text_to_image'den daha yüksek önceliğe sahiptir
|
| 31 |
+
image = client.text_to_image(
|
| 32 |
+
prompt,
|
| 33 |
+
model="stabilityai/stable-diffusion-xl-base-1.0", # Çok kararlı bir model
|
| 34 |
+
)
|
| 35 |
+
return image
|
| 36 |
+
except Exception as e:
|
| 37 |
+
# Eğer ilk model hata verirse, en temel modele dön
|
| 38 |
try:
|
|
|
|
| 39 |
return client.text_to_image(prompt, model="runwayml/stable-diffusion-v1-5")
|
| 40 |
except:
|
| 41 |
+
print(f"Görsel Hatası: {e}")
|
| 42 |
return None
|
| 43 |
|
| 44 |
+
# Arayüz (Modern Dark Tema)
|
| 45 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", neutral_hue="slate")) as demo:
|
| 46 |
+
gr.Markdown("<h1 style='text-align: center; color: #38bdf8;'>🚀 Maind AI Studio</h1>")
|
| 47 |
+
|
| 48 |
with gr.Tabs():
|
| 49 |
+
with gr.TabItem("💬 Akıllı Sohbet"):
|
| 50 |
gr.ChatInterface(fn=chat_fn)
|
| 51 |
+
|
| 52 |
+
with gr.TabItem("🎨 Görsel Oluştur"):
|
| 53 |
with gr.Row():
|
| 54 |
with gr.Column():
|
| 55 |
+
inp = gr.Textbox(label="Görsel Tarifi (İngilizce)", placeholder="Örn: A futuristic car in Istanbul...")
|
| 56 |
+
btn = gr.Button("Görseli Oluştur ✨", variant="primary")
|
| 57 |
with gr.Column():
|
| 58 |
+
out = gr.Image(label="Sonuç", type="pil") # PIL formatı daha garantidir
|
| 59 |
+
|
| 60 |
btn.click(fn=image_fn, inputs=inp, outputs=out)
|
| 61 |
|
| 62 |
demo.queue().launch()
|