Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -212,7 +212,6 @@ def get_streams():
|
|
212 |
top_p = 0.95
|
213 |
repetition_penalty = 1.0
|
214 |
|
215 |
-
|
216 |
generate_kwargs = dict(
|
217 |
temperature=temperature,
|
218 |
max_new_tokens=max_new_tokens,
|
@@ -221,17 +220,30 @@ def get_streams():
|
|
221 |
do_sample=True,
|
222 |
seed=42,
|
223 |
)
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
230 |
"""
|
|
|
231 |
formatted_prompt = format_prompt(prompt)
|
232 |
|
233 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=False, return_full_text=False)
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
|
237 |
|
|
|
212 |
top_p = 0.95
|
213 |
repetition_penalty = 1.0
|
214 |
|
|
|
215 |
generate_kwargs = dict(
|
216 |
temperature=temperature,
|
217 |
max_new_tokens=max_new_tokens,
|
|
|
220 |
do_sample=True,
|
221 |
seed=42,
|
222 |
)
|
223 |
+
|
224 |
+
prompt = """
|
225 |
+
You need to act as a recommendation engine.
|
226 |
+
List all 40+ streams/branches like Computer Science, Chemical Engineering, Aerospace, etc.
|
227 |
+
Note: Output should be a **valid JSON list**:
|
228 |
+
["branch1", "branch2", "branch3", ...]
|
229 |
+
Return only the list, **do not return text or explanations**.
|
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 |
+
try:
|
237 |
+
# Ensure output is valid JSON
|
238 |
+
cleaned_data = stream.strip()
|
239 |
+
if not cleaned_data.startswith("["):
|
240 |
+
raise ValueError("Invalid response format")
|
241 |
+
|
242 |
+
parsed_data = json.loads(cleaned_data)
|
243 |
+
return jsonify({"ans": parsed_data}) # Send as proper JSON
|
244 |
+
except Exception as e:
|
245 |
+
return jsonify({"error": "Invalid response format", "details": str(e)})
|
246 |
+
|
247 |
|
248 |
|
249 |
|