Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,10 +4,12 @@ import os
|
|
| 4 |
import re
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
|
|
|
|
|
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
API_URL = "https://router.huggingface.co/v1/chat/completions"
|
| 9 |
|
| 10 |
-
#
|
| 11 |
MODELLER = [
|
| 12 |
"meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8", "deepcogito/cogito-671b-v2.1-FP8",
|
| 13 |
"deepseek-ai/DeepSeek-V3.2-Exp", "Qwen/Qwen3.5-397B-A17B", "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8",
|
|
@@ -35,28 +37,40 @@ def handle_request():
|
|
| 35 |
global model_sayaci
|
| 36 |
secilen_model = MODELLER[model_sayaci % len(MODELLER)]
|
| 37 |
model_sayaci += 1
|
|
|
|
| 38 |
try:
|
| 39 |
data = request.get_json()
|
| 40 |
istatistikler = data.get("istatistikler", "")
|
|
|
|
| 41 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 42 |
payload = {
|
| 43 |
"model": secilen_model,
|
| 44 |
"messages": [
|
| 45 |
-
{"role": "system", "content": "
|
| 46 |
{"role": "user", "content": istatistikler}
|
| 47 |
],
|
| 48 |
-
"max_tokens":
|
| 49 |
"temperature": 0.0
|
| 50 |
}
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
if response.status_code == 200:
|
| 53 |
cevap = response.json()['choices'][0]['message']['content']
|
| 54 |
if "</think>" in cevap: cevap = cevap.split("</think>")[-1]
|
| 55 |
-
cevap = re.sub(r'(?i)(okay|let|here|rating|score|analysis|sure).*', '', cevap).strip()
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
return jsonify({"error": str(e)}), 500
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
|
|
|
| 62 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 4 |
import re
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
# Hugging Face Ayarları
|
| 9 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
API_URL = "https://router.huggingface.co/v1/chat/completions"
|
| 11 |
|
| 12 |
+
# ÇALIŞAN ELİT 50 MODEL
|
| 13 |
MODELLER = [
|
| 14 |
"meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8", "deepcogito/cogito-671b-v2.1-FP8",
|
| 15 |
"deepseek-ai/DeepSeek-V3.2-Exp", "Qwen/Qwen3.5-397B-A17B", "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8",
|
|
|
|
| 37 |
global model_sayaci
|
| 38 |
secilen_model = MODELLER[model_sayaci % len(MODELLER)]
|
| 39 |
model_sayaci += 1
|
| 40 |
+
|
| 41 |
try:
|
| 42 |
data = request.get_json()
|
| 43 |
istatistikler = data.get("istatistikler", "")
|
| 44 |
+
|
| 45 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 46 |
payload = {
|
| 47 |
"model": secilen_model,
|
| 48 |
"messages": [
|
| 49 |
+
{"role": "system", "content": "SADECE 'İsim: Puan' formatında cevap ver. 4.0-10.0 arası."},
|
| 50 |
{"role": "user", "content": istatistikler}
|
| 51 |
],
|
| 52 |
+
"max_tokens": 80,
|
| 53 |
"temperature": 0.0
|
| 54 |
}
|
| 55 |
+
|
| 56 |
+
response = requests.post(API_URL, headers=headers, json=payload, timeout=25)
|
| 57 |
+
|
| 58 |
if response.status_code == 200:
|
| 59 |
cevap = response.json()['choices'][0]['message']['content']
|
| 60 |
if "</think>" in cevap: cevap = cevap.split("</think>")[-1]
|
| 61 |
+
cevap = re.sub(r'(?i)(okay|let|here|rating|score|analysis|sure|certainly).*', '', cevap).strip()
|
| 62 |
+
|
| 63 |
+
return jsonify({
|
| 64 |
+
"model": secilen_model,
|
| 65 |
+
"puanlar": cevap.replace(".", ","),
|
| 66 |
+
"sayac": model_sayaci
|
| 67 |
+
})
|
| 68 |
+
|
| 69 |
+
return jsonify({"error": f"Model Hatası: {response.status_code}"}), response.status_code
|
| 70 |
+
|
| 71 |
except Exception as e:
|
| 72 |
return jsonify({"error": str(e)}), 500
|
| 73 |
|
| 74 |
if __name__ == "__main__":
|
| 75 |
+
# HF için PORT 7860 şarttır!
|
| 76 |
app.run(host="0.0.0.0", port=7860)
|