Update app.py
Browse files
app.py
CHANGED
|
@@ -4,55 +4,51 @@ import os
|
|
| 4 |
|
| 5 |
# Secret olarak eklediğin Token'ı al
|
| 6 |
token = os.getenv("HF_TOKEN")
|
| 7 |
-
|
| 8 |
-
# İstemciyi başlatıyoruz
|
| 9 |
client = InferenceClient(token=token)
|
| 10 |
|
| 11 |
def chat_fn(message, history):
|
| 12 |
try:
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Hata
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if token_str:
|
| 25 |
-
response += token_str
|
| 26 |
-
yield response
|
| 27 |
except Exception as e:
|
| 28 |
-
|
| 29 |
|
| 30 |
def image_fn(prompt):
|
| 31 |
if not prompt: return None
|
| 32 |
try:
|
| 33 |
# Görsel oluşturma
|
| 34 |
-
|
| 35 |
-
return image
|
| 36 |
except Exception as e:
|
| 37 |
-
print(f"Görsel Hatası: {e}")
|
| 38 |
return None
|
| 39 |
|
| 40 |
# Arayüz Ayarları
|
| 41 |
-
with gr.Blocks(theme=gr.themes.Soft(
|
| 42 |
-
gr.Markdown("<h1 style='text-align: center;'>🚀 Maind AI Studio</h1>")
|
| 43 |
|
| 44 |
with gr.Tabs():
|
| 45 |
-
with gr.TabItem("💬
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
with gr.TabItem("🎨 Görsel
|
| 49 |
with gr.Row():
|
| 50 |
with gr.Column():
|
| 51 |
-
inp = gr.Textbox(label="Görsel Tarifi (İngilizce)"
|
| 52 |
-
|
| 53 |
with gr.Column():
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
btn.click(fn=image_fn, inputs=inp, outputs=out)
|
| 57 |
|
| 58 |
-
demo.
|
|
|
|
| 4 |
|
| 5 |
# Secret olarak eklediğin Token'ı al
|
| 6 |
token = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
| 7 |
client = InferenceClient(token=token)
|
| 8 |
|
| 9 |
def chat_fn(message, history):
|
| 10 |
try:
|
| 11 |
+
# Chat arayüzünü bozmamak için basit bir prompt yapısı kuruyoruz
|
| 12 |
+
prompt = f"User: {message}\nAssistant:"
|
| 13 |
+
|
| 14 |
+
# En kararlı çalışan Llama-3 modelini doğrudan metin üretme ile çağırıyoruz
|
| 15 |
+
response = client.text_generation(
|
| 16 |
+
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
| 17 |
+
prompt=prompt,
|
| 18 |
+
max_new_tokens=500,
|
| 19 |
+
stream=False # Hata riskini azaltmak için stream'i kapattık
|
| 20 |
+
)
|
| 21 |
+
return response
|
|
|
|
|
|
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
+
return f"Hata: {str(e)}"
|
| 24 |
|
| 25 |
def image_fn(prompt):
|
| 26 |
if not prompt: return None
|
| 27 |
try:
|
| 28 |
# Görsel oluşturma
|
| 29 |
+
return client.text_to_image(prompt, model="stabilityai/sdxl-turbo")
|
|
|
|
| 30 |
except Exception as e:
|
|
|
|
| 31 |
return None
|
| 32 |
|
| 33 |
# Arayüz Ayarları
|
| 34 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 35 |
+
gr.Markdown("<h1 style='text-align: center; color: #38bdf8;'>🚀 Maind AI Studio</h1>")
|
| 36 |
|
| 37 |
with gr.Tabs():
|
| 38 |
+
with gr.TabItem("💬 Sohbet"):
|
| 39 |
+
# ChatInterface bazen karmaşık hata verebilir, manuel kurguluyoruz
|
| 40 |
+
msg = gr.Textbox(label="Mesajınızı yazın")
|
| 41 |
+
out_txt = gr.Textbox(label="Yanıt", interactive=False)
|
| 42 |
+
btn_txt = gr.Button("Gönder", variant="primary")
|
| 43 |
+
btn_txt.click(chat_fn, msg, out_txt)
|
| 44 |
|
| 45 |
+
with gr.TabItem("🎨 Görsel"):
|
| 46 |
with gr.Row():
|
| 47 |
with gr.Column():
|
| 48 |
+
inp = gr.Textbox(label="Görsel Tarifi (İngilizce)")
|
| 49 |
+
btn_img = gr.Button("Çiz ✨", variant="primary")
|
| 50 |
with gr.Column():
|
| 51 |
+
out_img = gr.Image()
|
| 52 |
+
btn_img.click(image_fn, inp, out_img)
|
|
|
|
| 53 |
|
| 54 |
+
demo.launch()
|