Teotonix commited on
Commit
1a90d60
·
verified ·
1 Parent(s): 920a956

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -2,35 +2,25 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # Secret olarak eklediğin tokenburadan çeker
6
  token = os.getenv("HF_TOKEN")
7
 
8
- # Eğer token boşsa hata vermemesi için kontrol ekledik
9
- if not token:
10
- print("UYARI: HF_TOKEN bulunamadı! Lütfen Settings -> Secrets kısmına ekleyin.")
11
-
12
- text_client = InferenceClient("TinyLlama/TinyLlama-1.1B-Chat-v1.0", token=token)
13
- image_client = InferenceClient("stabilityai/sdxl-turbo", token=token)
14
 
15
  def chat_fn(message, history):
16
  try:
17
- response = ""
18
- # Token ile güvenli bağlantı
19
- for msg in text_client.chat_completion(
20
- messages=[{"role": "user", "content": message}],
21
- max_tokens=500,
22
- stream=True,
23
- ):
24
- token_str = msg.choices[0].delta.content
25
- response += token_str
26
- yield response
27
  except Exception as e:
28
- yield f"Hata oluştu: {str(e)}"
29
 
30
  def image_fn(prompt):
31
  if not prompt: return None
32
  try:
33
- # Görsel oluşturma
34
  return image_client.text_to_image(prompt)
35
  except Exception as e:
36
  print(f"Görsel hatası: {e}")
@@ -40,14 +30,18 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
40
  gr.Markdown("# 🚀 Maind AI Studio")
41
  with gr.Tabs():
42
  with gr.TabItem("💬 Sohbet"):
43
- gr.ChatInterface(chat_fn)
 
 
 
 
44
  with gr.TabItem("🎨 Görsel"):
45
  with gr.Row():
46
  with gr.Column():
47
- inp = gr.Textbox(label="Tarif")
48
- btn = gr.Button("Çiz")
49
  with gr.Column():
50
- out = gr.Image()
51
- btn.click(image_fn, inp, out)
52
 
53
  demo.launch()
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
+ # Tokenal
6
  token = os.getenv("HF_TOKEN")
7
 
8
+ # Modelleri doğrudan URL ile tanımlayarak "Router" hatasını engelliyoruz
9
+ # Bu yöntem 403 Forbidden hatasını genellikle çözer
10
+ text_client = InferenceClient(model="https://api-inference.huggingface.co/models/TinyLlama/TinyLlama-1.1B-Chat-v1.0", token=token)
11
+ image_client = InferenceClient(model="https://api-inference.huggingface.co/models/stabilityai/sdxl-turbo", token=token)
 
 
12
 
13
  def chat_fn(message, history):
14
  try:
15
+ # ChatCompletion yerine doğrudan text_generation kullanıyoruz (Daha güvenli)
16
+ response = text_client.text_generation(message, max_new_tokens=500)
17
+ return response
 
 
 
 
 
 
 
18
  except Exception as e:
19
+ return f"Hata: {str(e)}"
20
 
21
  def image_fn(prompt):
22
  if not prompt: return None
23
  try:
 
24
  return image_client.text_to_image(prompt)
25
  except Exception as e:
26
  print(f"Görsel hatası: {e}")
 
30
  gr.Markdown("# 🚀 Maind AI Studio")
31
  with gr.Tabs():
32
  with gr.TabItem("💬 Sohbet"):
33
+ msg = gr.Textbox(label="Mesajın")
34
+ out_txt = gr.Textbox(label="Maind AI Yanıtı")
35
+ btn_txt = gr.Button("Gönder")
36
+ btn_txt.click(chat_fn, msg, out_txt)
37
+
38
  with gr.TabItem("🎨 Görsel"):
39
  with gr.Row():
40
  with gr.Column():
41
+ inp = gr.Textbox(label="Görsel Tarifi")
42
+ btn_img = gr.Button("Çiz")
43
  with gr.Column():
44
+ out_img = gr.Image()
45
+ btn_img.click(image_fn, inp, out_img)
46
 
47
  demo.launch()