Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,9 +10,9 @@ import requests
|
|
| 10 |
app = Flask(__name__)
|
| 11 |
CORS(app)
|
| 12 |
|
| 13 |
-
# ---
|
| 14 |
-
#
|
| 15 |
-
LLM_API_URL = "https://api-inference.huggingface.co/models/
|
| 16 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 17 |
|
| 18 |
@app.route('/')
|
|
@@ -51,12 +51,15 @@ def analyze():
|
|
| 51 |
if not HF_TOKEN:
|
| 52 |
return jsonify({"error": "Hugging Face API token is not configured on the server."}), 500
|
| 53 |
|
| 54 |
-
prompt
|
|
|
|
| 55 |
You are ReflectAI. A person's photo shows an expression of '{attributes['emotion']}', they are a {attributes['gender']} aged around {attributes['age']}.
|
| 56 |
Write a two-part response:
|
| 57 |
1. **Comment:** A short, insightful, and encouraging comment about their aura.
|
| 58 |
2. **Advice:** A brief, actionable piece of advice related to their expression or age.
|
| 59 |
-
Format the output with "Comment:" and "Advice:" labels. Do not repeat the attributes.<
|
|
|
|
|
|
|
| 60 |
<|assistant|>
|
| 61 |
"""
|
| 62 |
|
|
|
|
| 10 |
app = Flask(__name__)
|
| 11 |
CORS(app)
|
| 12 |
|
| 13 |
+
# --- FAILSAFE MODEL ENDPOINT ---
|
| 14 |
+
# Using TinyLlama, a reliable and non-gated model.
|
| 15 |
+
LLM_API_URL = "https://api-inference.huggingface.co/models/TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 16 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 17 |
|
| 18 |
@app.route('/')
|
|
|
|
| 51 |
if not HF_TOKEN:
|
| 52 |
return jsonify({"error": "Hugging Face API token is not configured on the server."}), 500
|
| 53 |
|
| 54 |
+
# This prompt format is optimized for TinyLlama/Zephyr models.
|
| 55 |
+
prompt = f"""<|system|>
|
| 56 |
You are ReflectAI. A person's photo shows an expression of '{attributes['emotion']}', they are a {attributes['gender']} aged around {attributes['age']}.
|
| 57 |
Write a two-part response:
|
| 58 |
1. **Comment:** A short, insightful, and encouraging comment about their aura.
|
| 59 |
2. **Advice:** A brief, actionable piece of advice related to their expression or age.
|
| 60 |
+
Format the output with "Comment:" and "Advice:" labels. Do not repeat the attributes.</s>
|
| 61 |
+
<|user|>
|
| 62 |
+
Generate the response.</s>
|
| 63 |
<|assistant|>
|
| 64 |
"""
|
| 65 |
|