Teotonix commited on
Commit
0dd8ac6
·
verified ·
1 Parent(s): 83456bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
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
- # 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()
 
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()