ki1207 commited on
Commit
3c3c65b
1 Parent(s): 9a4e757

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -15
app.py CHANGED
@@ -10,7 +10,7 @@ import PIL.Image
10
  import torch
11
  from transformers import InstructBlipProcessor, InstructBlipForConditionalGeneration
12
 
13
- DESCRIPTION = "# [BLIP-2 VQA Ad Listing Analysis](https://github.com/salesforce/LAVIS/tree/main/projects/blip2)"
14
 
15
  if not torch.cuda.is_available():
16
  DESCRIPTION += "\n<p>Running on CPU.</p>"
@@ -36,17 +36,7 @@ def answer_ad_listing_question(
36
  """
37
 
38
  inputs = processor(images=image, text=prompt, return_tensors="pt").to(device, torch.float16)
39
- generated_ids = model.generate(
40
- **inputs,
41
- do_sample=True, # Nucleus sampling is applied
42
- temperature=1.0, # Default temperature
43
- length_penalty=1.0, # Default length penalty
44
- repetition_penalty=1.5, # Default repetition penalty
45
- max_length=50, # Default max length
46
- min_length=1, # Default min length
47
- num_beams=5, # Default number of beams
48
- top_p=0.9, # Default top_p for nucleus sampling
49
- )
50
  result = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
51
  return result
52
 
@@ -61,14 +51,14 @@ with gr.Blocks() as demo:
61
  with gr.Group():
62
  # Image and ad title input
63
  image = gr.Image(type="pil")
64
- ad_title = gr.Textbox(label="Ad Title", placeholder="Enter the ad title here", lines=1)
65
 
66
  # Output section
67
- answer_output = gr.Textbox(label="Ad Listing Analysis", show_label=True, placeholder="Response will appear here.")
68
 
69
  # Submit and clear buttons
70
  with gr.Row():
71
- submit_button = gr.Button("Analyze Ad Listing", variant="primary")
72
  clear_button = gr.Button("Clear")
73
 
74
  # Logic to handle clicking on "Analyze Ad Listing"
 
10
  import torch
11
  from transformers import InstructBlipProcessor, InstructBlipForConditionalGeneration
12
 
13
+ DESCRIPTION = "# [BLIP-2 test](https://github.com/salesforce/LAVIS/tree/main/projects/blip2)"
14
 
15
  if not torch.cuda.is_available():
16
  DESCRIPTION += "\n<p>Running on CPU.</p>"
 
36
  """
37
 
38
  inputs = processor(images=image, text=prompt, return_tensors="pt").to(device, torch.float16)
39
+ generated_ids = model.generate(**inputs)
 
 
 
 
 
 
 
 
 
 
40
  result = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
41
  return result
42
 
 
51
  with gr.Group():
52
  # Image and ad title input
53
  image = gr.Image(type="pil")
54
+ ad_title = gr.Textbox(label="Advertisement Title", placeholder="Enter the title here", lines=1)
55
 
56
  # Output section
57
+ answer_output = gr.Textbox(label="Analysis", show_label=True, placeholder="Response.")
58
 
59
  # Submit and clear buttons
60
  with gr.Row():
61
+ submit_button = gr.Button("Analyze Listing", variant="primary")
62
  clear_button = gr.Button("Clear")
63
 
64
  # Logic to handle clicking on "Analyze Ad Listing"