Update app.py
Browse files
app.py
CHANGED
|
@@ -4,17 +4,17 @@ from llama_cpp import Llama
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
# -----------------------------
|
| 7 |
-
#
|
| 8 |
# -----------------------------
|
| 9 |
-
MODEL_REPO = "Qwen/Qwen2.5-3B-Instruct-GGUF"
|
| 10 |
-
MODEL_FILE = "qwen2.5-3b-instruct-q4_k_m.gguf"
|
| 11 |
MODEL_DIR = "data"
|
| 12 |
MODEL_PATH = os.path.join(MODEL_DIR, MODEL_FILE)
|
| 13 |
|
| 14 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 15 |
|
| 16 |
# -----------------------------
|
| 17 |
-
#
|
| 18 |
# -----------------------------
|
| 19 |
if not os.path.exists(MODEL_PATH):
|
| 20 |
print("🔽 Model indiriliyor...")
|
|
@@ -25,37 +25,45 @@ if not os.path.exists(MODEL_PATH):
|
|
| 25 |
)
|
| 26 |
print("✅ Model indirildi:", downloaded_path)
|
| 27 |
else:
|
| 28 |
-
print("⚡ Model zaten mevcut,
|
| 29 |
|
| 30 |
# -----------------------------
|
| 31 |
-
#
|
| 32 |
# -----------------------------
|
| 33 |
print("⏳ Model yükleniyor...")
|
| 34 |
llm = Llama(
|
| 35 |
model_path=MODEL_PATH,
|
| 36 |
n_ctx=4096,
|
| 37 |
-
n_threads=4,
|
| 38 |
-
n_gpu_layers=0
|
| 39 |
)
|
| 40 |
print("✅ Model yüklendi!")
|
| 41 |
|
|
|
|
| 42 |
# -----------------------------
|
| 43 |
-
#
|
| 44 |
# -----------------------------
|
| 45 |
def chat(prompt):
|
| 46 |
-
|
| 47 |
-
return
|
|
|
|
| 48 |
|
| 49 |
# -----------------------------
|
| 50 |
-
#
|
| 51 |
# -----------------------------
|
| 52 |
demo = gr.Interface(
|
| 53 |
fn=chat,
|
| 54 |
inputs=gr.Textbox(label="Soru"),
|
| 55 |
outputs=gr.Textbox(label="Cevap"),
|
| 56 |
-
title="Qwen 3B Instruct (GGUF -
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
# -----------------------------
|
| 7 |
+
# MODEL AYARLARI
|
| 8 |
# -----------------------------
|
| 9 |
+
MODEL_REPO = "Qwen/Qwen2.5-3B-Instruct-GGUF"
|
| 10 |
+
MODEL_FILE = "qwen2.5-3b-instruct-q4_k_m.gguf"
|
| 11 |
MODEL_DIR = "data"
|
| 12 |
MODEL_PATH = os.path.join(MODEL_DIR, MODEL_FILE)
|
| 13 |
|
| 14 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 15 |
|
| 16 |
# -----------------------------
|
| 17 |
+
# MODEL İNDİR (YOKSA)
|
| 18 |
# -----------------------------
|
| 19 |
if not os.path.exists(MODEL_PATH):
|
| 20 |
print("🔽 Model indiriliyor...")
|
|
|
|
| 25 |
)
|
| 26 |
print("✅ Model indirildi:", downloaded_path)
|
| 27 |
else:
|
| 28 |
+
print("⚡ Model zaten mevcut, indirme atlandı.")
|
| 29 |
|
| 30 |
# -----------------------------
|
| 31 |
+
# MODEL YÜKLE
|
| 32 |
# -----------------------------
|
| 33 |
print("⏳ Model yükleniyor...")
|
| 34 |
llm = Llama(
|
| 35 |
model_path=MODEL_PATH,
|
| 36 |
n_ctx=4096,
|
| 37 |
+
n_threads=4,
|
| 38 |
+
n_gpu_layers=0
|
| 39 |
)
|
| 40 |
print("✅ Model yüklendi!")
|
| 41 |
|
| 42 |
+
|
| 43 |
# -----------------------------
|
| 44 |
+
# CHAT ÇALIŞTIR
|
| 45 |
# -----------------------------
|
| 46 |
def chat(prompt):
|
| 47 |
+
out = llm(prompt, max_tokens=300, temperature=0.7)
|
| 48 |
+
return out["choices"][0]["text"]
|
| 49 |
+
|
| 50 |
|
| 51 |
# -----------------------------
|
| 52 |
+
# GRADIO ARAYÜZÜ (HF PRIVATE MODE UYUMLU)
|
| 53 |
# -----------------------------
|
| 54 |
demo = gr.Interface(
|
| 55 |
fn=chat,
|
| 56 |
inputs=gr.Textbox(label="Soru"),
|
| 57 |
outputs=gr.Textbox(label="Cevap"),
|
| 58 |
+
title="Qwen 3B Instruct (GGUF - Private HF Space)"
|
| 59 |
)
|
| 60 |
|
| 61 |
+
# ❗ HuggingFace PRIVATE mod için kritik ayar:
|
| 62 |
+
demo.launch(
|
| 63 |
+
server_name="0.0.0.0",
|
| 64 |
+
server_port=7860,
|
| 65 |
+
show_error=True,
|
| 66 |
+
share=False, # PRIVATE SPACE olduğunda zorunlu
|
| 67 |
+
ssr_mode=False, # Node.js çakışmasını çözer
|
| 68 |
+
inbrowser=False # HF iframe preview uyumlu
|
| 69 |
+
)
|