Update app.py
Browse files
app.py
CHANGED
|
@@ -11,34 +11,31 @@ client = InferenceClient(token=token)
|
|
| 11 |
def chat_fn(message, history):
|
| 12 |
try:
|
| 13 |
response = ""
|
| 14 |
-
#
|
| 15 |
for msg in client.chat_completion(
|
| 16 |
-
model="
|
| 17 |
messages=[{"role": "user", "content": message}],
|
| 18 |
max_tokens=500,
|
| 19 |
stream=True,
|
| 20 |
):
|
| 21 |
-
|
| 22 |
-
if
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
-
yield f"Sohbet Hatası: {str(e)}"
|
| 27 |
|
| 28 |
def image_fn(prompt):
|
| 29 |
if not prompt: return None
|
| 30 |
try:
|
| 31 |
-
# Görsel
|
| 32 |
image = client.text_to_image(prompt, model="stabilityai/sdxl-turbo")
|
| 33 |
return image
|
| 34 |
except Exception as e:
|
| 35 |
-
|
| 36 |
-
|
| 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:
|
|
@@ -51,7 +48,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
|
| 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")
|
|
|
|
| 11 |
def chat_fn(message, history):
|
| 12 |
try:
|
| 13 |
response = ""
|
| 14 |
+
# Mistral-7B, ücretsiz API'da en kararlı çalışan modeldir
|
| 15 |
for msg in client.chat_completion(
|
| 16 |
+
model="mistralai/Mistral-7B-Instruct-v0.3",
|
| 17 |
messages=[{"role": "user", "content": message}],
|
| 18 |
max_tokens=500,
|
| 19 |
stream=True,
|
| 20 |
):
|
| 21 |
+
# Hata kontrolü: Eğer mesaj içeriği varsa ekle
|
| 22 |
+
if msg.choices and len(msg.choices) > 0:
|
| 23 |
+
token_str = msg.choices[0].delta.content
|
| 24 |
+
if token_str:
|
| 25 |
+
response += token_str
|
| 26 |
+
yield response
|
| 27 |
except Exception as e:
|
| 28 |
+
yield f"Sohbet Hatası: Teknik bir aksaklık oldu, lütfen tekrar deneyin. (Detay: {str(e)})"
|
| 29 |
|
| 30 |
def image_fn(prompt):
|
| 31 |
if not prompt: return None
|
| 32 |
try:
|
| 33 |
+
# Görsel oluşturma
|
| 34 |
image = client.text_to_image(prompt, model="stabilityai/sdxl-turbo")
|
| 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(primary_hue="blue")) as demo:
|
|
|
|
| 48 |
with gr.TabItem("🎨 Görsel Oluştur"):
|
| 49 |
with gr.Row():
|
| 50 |
with gr.Column():
|
| 51 |
+
inp = gr.Textbox(label="Görsel Tarifi (İngilizce)", placeholder="Örn: A cute cat astronaut...")
|
| 52 |
btn = gr.Button("Sihri Başlat ✨", variant="primary")
|
| 53 |
with gr.Column():
|
| 54 |
out = gr.Image(label="Üretilen Görsel")
|