Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -220,24 +220,31 @@ def get_streams():
|
|
220 |
do_sample=True,
|
221 |
seed=42,
|
222 |
)
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
227 |
["Artificial Intelligence", "Computer Science", "Data Science", "Cyber Security", ...]
|
228 |
-
|
229 |
-
|
|
|
230 |
formatted_prompt = format_prompt(prompt)
|
231 |
|
232 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=False, return_full_text=False)
|
233 |
|
234 |
-
#
|
|
|
|
|
|
|
235 |
try:
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
238 |
return jsonify({"error": "Invalid response format"}), 500
|
239 |
-
|
240 |
-
return jsonify({"ans": stream_list})
|
241 |
|
242 |
|
243 |
|
|
|
220 |
do_sample=True,
|
221 |
seed=42,
|
222 |
)
|
223 |
+
|
224 |
+
# Updated prompt to enforce strict JSON output
|
225 |
+
prompt = """You are a recommendation engine.
|
226 |
+
List 40+ academic streams like "Artificial Intelligence", "Chemical Engineering", etc.
|
227 |
+
Output **must be** a valid JSON array **without extra text**:
|
228 |
["Artificial Intelligence", "Computer Science", "Data Science", "Cyber Security", ...]
|
229 |
+
No additional formatting, no extra text, just the JSON array.
|
230 |
+
"""
|
231 |
+
|
232 |
formatted_prompt = format_prompt(prompt)
|
233 |
|
234 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=False, return_full_text=False)
|
235 |
|
236 |
+
# Debugging: Print raw API response
|
237 |
+
print("Raw API Response:", stream)
|
238 |
+
|
239 |
+
# Clean and validate response
|
240 |
try:
|
241 |
+
stream_cleaned = stream.strip().replace("\n", "").replace("`", "").replace("json", "")
|
242 |
+
stream_list = json.loads(stream_cleaned) # Convert string to Python list
|
243 |
+
return jsonify({"ans": stream_list})
|
244 |
+
except json.JSONDecodeError as e:
|
245 |
+
print("JSON Decode Error:", e)
|
246 |
return jsonify({"error": "Invalid response format"}), 500
|
247 |
+
|
|
|
248 |
|
249 |
|
250 |
|