1inkusFace commited on
Commit
b4eb9ed
·
verified ·
1 Parent(s): 494b48a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -251,8 +251,10 @@ def captioning(img):
251
  # Add more prompts here
252
  ]
253
  output_prompt=[]
254
- # Initial caption generation without a prompt:
255
- inputsa = processor5(images=img, return_tensors="pt").to('cuda')
 
 
256
  generated_ids = model5.generate(
257
  **inputsa,
258
  do_sample=False,
@@ -263,7 +265,7 @@ def captioning(img):
263
  repetition_penalty=1.5,
264
  length_penalty=1.0,
265
  temperature=1,
266
- )
267
 
268
  generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
269
  output_prompt.append(generated_text)
@@ -272,16 +274,16 @@ def captioning(img):
272
  for prompt in prompts_array:
273
  inputs = processor5(images=img, text=prompt, return_tensors="pt").to('cuda')
274
  generated_ids = model5.generate(
275
- **inputs,
276
- do_sample=False,
277
- num_beams=5,
278
- max_length=256,
279
- min_length=1,
280
- top_p=0.9,
281
- repetition_penalty=1.5,
282
- length_penalty=1.0,
283
- temperature=1,
284
- )
285
  # Adjust max_length if needed
286
  generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
287
  response_text = generated_text.replace(prompt, "").strip() #Or could try .split(prompt, 1)[-1].strip()
 
251
  # Add more prompts here
252
  ]
253
  output_prompt=[]
254
+ cap_prompt = (
255
+ "Describe this image with a caption."
256
+ )
257
+ inputsa = processor5(images=img, text=cap_prompt, return_tensors="pt").to('cuda')
258
  generated_ids = model5.generate(
259
  **inputsa,
260
  do_sample=False,
 
265
  repetition_penalty=1.5,
266
  length_penalty=1.0,
267
  temperature=1,
268
+ )
269
 
270
  generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
271
  output_prompt.append(generated_text)
 
274
  for prompt in prompts_array:
275
  inputs = processor5(images=img, text=prompt, return_tensors="pt").to('cuda')
276
  generated_ids = model5.generate(
277
+ **inputs,
278
+ do_sample=False,
279
+ num_beams=5,
280
+ max_length=128,
281
+ min_length=1,
282
+ top_p=0.9,
283
+ repetition_penalty=1.5,
284
+ length_penalty=1.0,
285
+ temperature=1,
286
+ )
287
  # Adjust max_length if needed
288
  generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
289
  response_text = generated_text.replace(prompt, "").strip() #Or could try .split(prompt, 1)[-1].strip()