Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,39 +4,34 @@ import os
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
| 7 |
-
#
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
-
|
| 10 |
-
# En stabil model ve doğru router adresi
|
| 11 |
API_URL = "https://router.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
| 12 |
|
| 13 |
@app.route("/", methods=["POST"])
|
| 14 |
def handle_request():
|
| 15 |
try:
|
| 16 |
data = request.get_json()
|
| 17 |
-
soru = data.get("soru", "
|
| 18 |
-
|
| 19 |
-
headers = {
|
| 20 |
-
"Authorization": f"Bearer {HF_TOKEN}",
|
| 21 |
-
"Content-Type": "application/json"
|
| 22 |
-
}
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
"parameters": {"max_new_tokens": 150, "wait_for_model": True}
|
| 27 |
-
}
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
response = requests.post(API_URL, headers=headers, json=payload, timeout=
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
if
|
| 34 |
-
return jsonify({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
return jsonify(response.json())
|
| 37 |
|
| 38 |
except Exception as e:
|
| 39 |
-
return jsonify({"error": "
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
| 7 |
+
# Settings -> Secrets kısmındaki ismiyle birebir aynı olmalı
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
| 9 |
API_URL = "https://router.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
| 10 |
|
| 11 |
@app.route("/", methods=["POST"])
|
| 12 |
def handle_request():
|
| 13 |
try:
|
| 14 |
data = request.get_json()
|
| 15 |
+
soru = data.get("soru", "Messi vs Ronaldo")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"}
|
| 18 |
+
payload = {"inputs": soru, "parameters": {"max_new_tokens": 100}}
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# İSTEĞİ GÖNDER
|
| 21 |
+
response = requests.post(API_URL, headers=headers, json=payload, timeout=20)
|
| 22 |
|
| 23 |
+
# EĞER HUGGING FACE HATA VERİRSE DETAYI GODOT'YA YOLLA
|
| 24 |
+
if response.status_code != 200:
|
| 25 |
+
return jsonify({
|
| 26 |
+
"error": "HF_HATASI",
|
| 27 |
+
"detay": response.text,
|
| 28 |
+
"kod": response.status_code
|
| 29 |
+
}), response.status_code
|
| 30 |
|
| 31 |
return jsonify(response.json())
|
| 32 |
|
| 33 |
except Exception as e:
|
| 34 |
+
return jsonify({"error": "FLASK_HATASI", "detay": str(e)}), 500
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
app.run(host="0.0.0.0", port=7860)
|