Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,14 @@ HF_TOKEN = os.environ.get("HF_TOKEN") # Токен должен быть доб
|
|
8 |
def generate_response(user_text):
|
9 |
API_URL = "https://api-inference.huggingface.co/models/tinkoff-ai/ruDialoGPT-medium"
|
10 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
@app.route("/chat", methods=["POST"])
|
15 |
def chat():
|
|
|
8 |
def generate_response(user_text):
|
9 |
API_URL = "https://api-inference.huggingface.co/models/tinkoff-ai/ruDialoGPT-medium"
|
10 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
11 |
+
try:
|
12 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": user_text, "wait_for_model": True})
|
13 |
+
if response.status_code == 200:
|
14 |
+
return response.json()[0]["generated_text"]
|
15 |
+
else:
|
16 |
+
return f"Ошибка: {response.status_code} - {response.text}"
|
17 |
+
except Exception as e:
|
18 |
+
return f"Ошибка при запросе к модели: {str(e)}"
|
19 |
|
20 |
@app.route("/chat", methods=["POST"])
|
21 |
def chat():
|