kevalfst commited on
Commit
3c742aa
Β·
verified Β·
1 Parent(s): 0c46b11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
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
- # Make the instruction explicit: return ONLY JSON, without explanation
12
  instruction = (
13
- f"Generate only a valid JSON object without any markdown or additional text. "
14
- f"The JSON object should have the following keys: title, author, and tags. "
15
- f"Fill in dummy values. Now create a JSON object for: {prompt}"
 
 
16
  )
17
- result = generator(instruction, max_length=256, do_sample=False)
18
- generated_text = result[0]["generated_text"].strip() # remove extra whitespace
19
 
20
- print(f"Raw Model Output: {generated_text}") # Debug statement
 
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)