Spaces:
Paused
Paused
Debug
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
app = Flask(__name__)
|
5 |
client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct")
|
6 |
|
7 |
DEFAULT_MAX_TOKENS = 512
|
@@ -14,9 +13,10 @@ def generate_journal_suggestion(current_page):
|
|
14 |
f"""Pe baza înregistrării din jurnal: '{current_page}', generează o singură întrebare pe care utilizatorul ar putea să și-o pună în jurnalul său.
|
15 |
Întrebarea ar trebui să încurajeze reflecția personală mai profundă, explorarea sentimentelor sau clarificarea obiectivelor."""
|
16 |
)
|
|
|
|
|
17 |
suggestion_response = ""
|
18 |
-
|
19 |
-
for message in client.chat_completion(
|
20 |
[
|
21 |
{"role": "user", "content": suggestion_prompt}
|
22 |
],
|
@@ -24,16 +24,20 @@ def generate_journal_suggestion(current_page):
|
|
24 |
stream=True,
|
25 |
temperature=DEFAULT_TEMPERATURE,
|
26 |
top_p=DEFAULT_TOP_P,
|
27 |
-
)
|
|
|
|
|
|
|
|
|
28 |
token = message.choices[0].delta.content
|
29 |
suggestion_response += token
|
30 |
-
|
31 |
return suggestion_response
|
|
|
32 |
except Exception as e:
|
33 |
-
print(e)
|
34 |
return jsonify({"error": str(e)}), 500
|
35 |
|
36 |
-
|
37 |
@app.route("/", methods=["POST", "GET"])
|
38 |
def home():
|
39 |
return "Hi!"
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
4 |
client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct")
|
5 |
|
6 |
DEFAULT_MAX_TOKENS = 512
|
|
|
13 |
f"""Pe baza înregistrării din jurnal: '{current_page}', generează o singură întrebare pe care utilizatorul ar putea să și-o pună în jurnalul său.
|
14 |
Întrebarea ar trebui să încurajeze reflecția personală mai profundă, explorarea sentimentelor sau clarificarea obiectivelor."""
|
15 |
)
|
16 |
+
print("Generated suggestion prompt:", suggestion_prompt)
|
17 |
+
|
18 |
suggestion_response = ""
|
19 |
+
response_stream = client.chat_completion(
|
|
|
20 |
[
|
21 |
{"role": "user", "content": suggestion_prompt}
|
22 |
],
|
|
|
24 |
stream=True,
|
25 |
temperature=DEFAULT_TEMPERATURE,
|
26 |
top_p=DEFAULT_TOP_P,
|
27 |
+
)
|
28 |
+
print("Response stream received.")
|
29 |
+
|
30 |
+
for message in response_stream:
|
31 |
+
print("Message received:", message)
|
32 |
token = message.choices[0].delta.content
|
33 |
suggestion_response += token
|
34 |
+
|
35 |
return suggestion_response
|
36 |
+
|
37 |
except Exception as e:
|
38 |
+
print("An error occurred:", e)
|
39 |
return jsonify({"error": str(e)}), 500
|
40 |
|
|
|
41 |
@app.route("/", methods=["POST", "GET"])
|
42 |
def home():
|
43 |
return "Hi!"
|