Spaces:
Runtime error
Runtime error
Update app.py
Browse files7 unmodified lines891011121314151617181920212223247 unmodified linesgenerator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)def generate_json(prompt):# Ensure the prompt clearly asks for JSON outputinstruction = 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"]try:# Try to parse the text as JSONparsed = json.loads(generated_text)formatted_json = json.dumps(parsed, indent=2)except Exception as e:# Return raw text if parsing failsformatted_json = f"Raw Output:\n{generated_text}\n\nError parsing JSON: {e}"return formatted_json7 unmodified lines8910111213141516171819202122232425267 unmodified linesgenerator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)def generate_json(prompt):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 inspectprint(f"Raw Model Output: {generated_text}")try:# Try parsing the generated text as JSONparsed = json.loads(generated_text)formatted_json = json.dumps(parsed, indent=2)except Exception as e:# If parsing fails, print the errorformatted_json = f"Raw Output:\n{generated_text}\n\nError parsing JSON: {e}"return formatted_json
app.py+5-3