Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import gdown
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import subprocess
|
| 7 |
+
|
| 8 |
+
# Model linki (Drive paylaşılan)
|
| 9 |
+
DRIVE_LINK = "https://drive.google.com/uc?id=1OlQWjcevXx-Zw0XXGXK4qyWYW2GP7IaB"
|
| 10 |
+
MODEL_PATH = "ggml-alpaca-7b-q4.bin"
|
| 11 |
+
|
| 12 |
+
# Modeli indir (eğer yoksa)
|
| 13 |
+
if not Path(MODEL_PATH).exists():
|
| 14 |
+
print("Model indiriliyor...")
|
| 15 |
+
gdown.download(DRIVE_LINK, MODEL_PATH, quiet=False)
|
| 16 |
+
else:
|
| 17 |
+
print("Model zaten mevcut.")
|
| 18 |
+
|
| 19 |
+
# CPU için llama.cpp ile çalıştırma fonksiyonu
|
| 20 |
+
def generate(prompt):
|
| 21 |
+
# llama.cpp'nin ana binary'si 'main' olarak varsayılıyor
|
| 22 |
+
# Eğer farklıysa yolu güncelle
|
| 23 |
+
cmd = [
|
| 24 |
+
"./main", # llama.cpp binary
|
| 25 |
+
"-m", MODEL_PATH,
|
| 26 |
+
"-p", prompt,
|
| 27 |
+
"-n", "128", # max token
|
| 28 |
+
"-t", "4" # CPU thread sayısı (düzenle)
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 33 |
+
output = result.stdout
|
| 34 |
+
return output
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Hata: {e}"
|
| 37 |
+
|
| 38 |
+
# Gradio arayüzü
|
| 39 |
+
iface = gr.Interface(
|
| 40 |
+
fn=generate,
|
| 41 |
+
inputs=gr.Textbox(lines=3, placeholder="Prompt yaz..."),
|
| 42 |
+
outputs="text",
|
| 43 |
+
title="Alpaca-7B Q4 CPU",
|
| 44 |
+
description="Google Drive'dan indirilen Q4 quantized Alpaca modelini CPU üzerinde çalıştırır."
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# Arayüzü başlat
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
iface.launch()
|