Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,17 +8,19 @@ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
8 |
generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
def generate_json(prompt):
|
11 |
-
# Ensure the prompt clearly asks for JSON output
|
12 |
instruction = f"Generate a JSON object with the following properties: {prompt}"
|
13 |
result = generator(instruction, max_length=256, do_sample=False)
|
14 |
generated_text = result[0]["generated_text"]
|
15 |
|
|
|
|
|
|
|
16 |
try:
|
17 |
-
# Try
|
18 |
parsed = json.loads(generated_text)
|
19 |
formatted_json = json.dumps(parsed, indent=2)
|
20 |
except Exception as e:
|
21 |
-
#
|
22 |
formatted_json = f"Raw Output:\n{generated_text}\n\nError parsing JSON: {e}"
|
23 |
|
24 |
return formatted_json
|
|
|
8 |
generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
def generate_json(prompt):
|
|
|
11 |
instruction = f"Generate a JSON object with the following properties: {prompt}"
|
12 |
result = generator(instruction, max_length=256, do_sample=False)
|
13 |
generated_text = result[0]["generated_text"]
|
14 |
|
15 |
+
# Debug: Print raw model output to inspect
|
16 |
+
print(f"Raw Model Output: {generated_text}")
|
17 |
+
|
18 |
try:
|
19 |
+
# Try parsing the generated text as JSON
|
20 |
parsed = json.loads(generated_text)
|
21 |
formatted_json = json.dumps(parsed, indent=2)
|
22 |
except Exception as e:
|
23 |
+
# If parsing fails, print the error
|
24 |
formatted_json = f"Raw Output:\n{generated_text}\n\nError parsing JSON: {e}"
|
25 |
|
26 |
return formatted_json
|