Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,16 +8,19 @@ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
8 |
generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
def generate_json(prompt):
|
11 |
-
#
|
12 |
instruction = (
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
)
|
17 |
-
result = generator(instruction, max_length=
|
18 |
-
generated_text = result[0]["generated_text"].strip()
|
19 |
|
20 |
-
print
|
|
|
21 |
|
22 |
try:
|
23 |
parsed = json.loads(generated_text)
|
|
|
8 |
generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
def generate_json(prompt):
|
11 |
+
# Revise the instruction to make it explicit for valid JSON output
|
12 |
instruction = (
|
13 |
+
"Return only a valid JSON object, with no additional text. "
|
14 |
+
"The JSON object must contain exactly the keys: "
|
15 |
+
'"title", "author", "tags". '
|
16 |
+
"For the following prompt, generate this JSON object. "
|
17 |
+
f"Prompt: {prompt}"
|
18 |
)
|
19 |
+
result = generator(instruction, max_length=512, do_sample=False)
|
20 |
+
generated_text = result[0]["generated_text"].strip()
|
21 |
|
22 |
+
# Debug: print the raw output to inspect the format
|
23 |
+
print(f"Raw Model Output: {generated_text}")
|
24 |
|
25 |
try:
|
26 |
parsed = json.loads(generated_text)
|