Spaces:
Runtime error
Runtime error
Update app.py
Browse files7 unmodified lines8910111112131415161718171920212221232425267 unmodified linesgenerator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
def generate_json(prompt): # Ensure the prompt clearly asks for JSON output instruction = f"Generate a JSON object with the following properties: {prompt}" result = generator(instruction, max_length=256, do_sample=False) generated_text = result[0]["generated_text"] # Debug: Print raw model output to inspect print(f"Raw Model Output: {generated_text}")
try: # Try to parse the text as JSON # Try parsing the generated text as JSON parsed = json.loads(generated_text) formatted_json = json.dumps(parsed, indent=2) except Exception as e: # Return raw text if parsing fails # If parsing fails, print the error formatted_json = f"Raw Output:\n{generated_text}\n\nError parsing JSON: {e}"
return formatted_jsonapp.py+5-3