Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -250,14 +250,14 @@ def captioning(img):
|
|
250 |
output_prompt=[]
|
251 |
# Initial caption generation without a prompt:
|
252 |
inputsa = processor5(images=img, return_tensors="pt").to('cuda')
|
253 |
-
generated_ids = model5.generate(**inputsa, min_length=42, max_length=
|
254 |
generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
255 |
output_prompt.append(generated_text)
|
256 |
print(generated_text)
|
257 |
# Loop through prompts array:
|
258 |
for prompt in prompts_array:
|
259 |
inputs = processor5(images=img, text=prompt, return_tensors="pt").to('cuda')
|
260 |
-
generated_ids = model5.generate(**inputs, min_length=
|
261 |
generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
262 |
response_text = generated_text.replace(prompt, "").strip() #Or could try .split(prompt, 1)[-1].strip()
|
263 |
output_prompt.append(response_text)
|
@@ -271,6 +271,9 @@ def captioning(img):
|
|
271 |
#output_prompt.append(response_text)
|
272 |
print(output_prompt)
|
273 |
return output_prompt
|
|
|
|
|
|
|
274 |
|
275 |
def expand_prompt(prompt):
|
276 |
system_prompt_rewrite = (
|
@@ -309,7 +312,7 @@ def expand_prompt(prompt):
|
|
309 |
outputs_2 = model.generate(
|
310 |
input_ids=input_ids_2,
|
311 |
attention_mask=attention_mask_2,
|
312 |
-
max_new_tokens=
|
313 |
temperature=0.2,
|
314 |
top_p=0.9,
|
315 |
do_sample=True,
|
@@ -404,6 +407,10 @@ def generate_30(
|
|
404 |
print("-- using image file --")
|
405 |
print(caption)
|
406 |
print(caption_2)
|
|
|
|
|
|
|
|
|
407 |
print("-- generating further caption --")
|
408 |
global model5
|
409 |
global processor5
|
|
|
250 |
output_prompt=[]
|
251 |
# Initial caption generation without a prompt:
|
252 |
inputsa = processor5(images=img, return_tensors="pt").to('cuda')
|
253 |
+
generated_ids = model5.generate(**inputsa, min_length=42, max_length=128)
|
254 |
generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
255 |
output_prompt.append(generated_text)
|
256 |
print(generated_text)
|
257 |
# Loop through prompts array:
|
258 |
for prompt in prompts_array:
|
259 |
inputs = processor5(images=img, text=prompt, return_tensors="pt").to('cuda')
|
260 |
+
generated_ids = model5.generate(**inputs, min_length=32, max_length=64) # Adjust max_length if needed
|
261 |
generated_text = processor5.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
262 |
response_text = generated_text.replace(prompt, "").strip() #Or could try .split(prompt, 1)[-1].strip()
|
263 |
output_prompt.append(response_text)
|
|
|
271 |
#output_prompt.append(response_text)
|
272 |
print(output_prompt)
|
273 |
return output_prompt
|
274 |
+
|
275 |
+
def flatten_and_stringify(data):
|
276 |
+
return [str(item) for sublist in data if isinstance(sublist, list) for item in flatten_and_stringify(sublist) ] + [str(item) for item in data if not isinstance(item, list)]
|
277 |
|
278 |
def expand_prompt(prompt):
|
279 |
system_prompt_rewrite = (
|
|
|
312 |
outputs_2 = model.generate(
|
313 |
input_ids=input_ids_2,
|
314 |
attention_mask=attention_mask_2,
|
315 |
+
max_new_tokens=1024,
|
316 |
temperature=0.2,
|
317 |
top_p=0.9,
|
318 |
do_sample=True,
|
|
|
407 |
print("-- using image file --")
|
408 |
print(caption)
|
409 |
print(caption_2)
|
410 |
+
caption = flatten_and_stringify(caption)
|
411 |
+
caption = " ".join(caption)
|
412 |
+
caption_2 = flatten_and_stringify(caption_2)
|
413 |
+
caption_2 = " ".join(caption_2)
|
414 |
print("-- generating further caption --")
|
415 |
global model5
|
416 |
global processor5
|