Teotonix commited on
Commit
1112ccd
·
verified ·
1 Parent(s): 693726b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # Secret olarak eklediğin yeni Token'ı al
6
  token = os.getenv("HF_TOKEN")
7
 
8
  # İstemciyi başlatıyoruz
@@ -10,10 +10,10 @@ client = InferenceClient(token=token)
10
 
11
  def chat_fn(message, history):
12
  try:
13
- # Yeni router sistemi üzerinden sohbet
14
  response = ""
 
15
  for msg in client.chat_completion(
16
- model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
17
  messages=[{"role": "user", "content": message}],
18
  max_tokens=500,
19
  stream=True,
@@ -28,35 +28,34 @@ def chat_fn(message, history):
28
  def image_fn(prompt):
29
  if not prompt: return None
30
  try:
31
- # Yeni router sistemi üzerinden görsel (SDXL Turbo)
32
- # Bu model hızlı olduğu için tercih edildi
33
  image = client.text_to_image(prompt, model="stabilityai/sdxl-turbo")
34
  return image
35
  except Exception as e:
36
- print(f"Görsel Hatası: {e}")
37
- return None
 
 
 
 
 
38
 
39
- # Şık ve Tek Sayfada Arayüz
40
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan")) as demo:
41
  gr.Markdown("<h1 style='text-align: center;'>🚀 Maind AI Studio</h1>")
42
 
43
  with gr.Tabs():
44
  with gr.TabItem("💬 Akıllı Sohbet"):
45
- gr.ChatInterface(
46
- fn=chat_fn,
47
- examples=["Merhaba, nasılsın?", "Bana bir hikaye anlat."],
48
- cache_examples=False
49
- )
50
 
51
  with gr.TabItem("🎨 Görsel Oluştur"):
52
  with gr.Row():
53
  with gr.Column():
54
- inp = gr.Textbox(label="Hayalindeki Görsel", placeholder="Futuristic city, neon lights, 4k...")
55
  btn = gr.Button("Sihri Başlat ✨", variant="primary")
56
  with gr.Column():
57
  out = gr.Image(label="Üretilen Görsel")
58
 
59
  btn.click(fn=image_fn, inputs=inp, outputs=out)
60
 
61
- # Kuyruğu başlat ve yayına al
62
  demo.queue().launch()
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
+ # Secret olarak eklediğin Token'ı al
6
  token = os.getenv("HF_TOKEN")
7
 
8
  # İstemciyi başlatıyoruz
 
10
 
11
  def chat_fn(message, history):
12
  try:
 
13
  response = ""
14
+ # Daha popüler ve desteklenen bir model seçtik: Llama-3-8B
15
  for msg in client.chat_completion(
16
+ model="meta-llama/Meta-Llama-3-8B-Instruct",
17
  messages=[{"role": "user", "content": message}],
18
  max_tokens=500,
19
  stream=True,
 
28
  def image_fn(prompt):
29
  if not prompt: return None
30
  try:
31
+ # Görsel modeli aynı kalabilir, SDXL Turbo genellikle desteklenir
 
32
  image = client.text_to_image(prompt, model="stabilityai/sdxl-turbo")
33
  return image
34
  except Exception as e:
35
+ # Eğer görsel modeli de hata verirse alternatif modele yönlendirir
36
+ try:
37
+ image = client.text_to_image(prompt, model="runwayml/stable-diffusion-v1-5")
38
+ return image
39
+ except:
40
+ print(f"Görsel Hatası: {e}")
41
+ return None
42
 
43
+ # Arayüz Ayarları
44
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
45
  gr.Markdown("<h1 style='text-align: center;'>🚀 Maind AI Studio</h1>")
46
 
47
  with gr.Tabs():
48
  with gr.TabItem("💬 Akıllı Sohbet"):
49
+ gr.ChatInterface(fn=chat_fn)
 
 
 
 
50
 
51
  with gr.TabItem("🎨 Görsel Oluştur"):
52
  with gr.Row():
53
  with gr.Column():
54
+ inp = gr.Textbox(label="Görsel Tarifi (İngilizce)")
55
  btn = gr.Button("Sihri Başlat ✨", variant="primary")
56
  with gr.Column():
57
  out = gr.Image(label="Üretilen Görsel")
58
 
59
  btn.click(fn=image_fn, inputs=inp, outputs=out)
60
 
 
61
  demo.queue().launch()