Ashrafb commited on
Commit
c59f00d
·
1 Parent(s): 2a2f92a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -46,12 +46,14 @@ config.blip_num_beams = 64
46
  ci = Interrogator(config)
47
 
48
  def inference(input_image, mode, best_max_flavors):
49
- # Convert uploaded image to bytes
50
- image_bytes = input_image.read()
 
 
51
 
52
  # Process the image and generate prompt results based on the selected mode
53
- image = Image.open(io.BytesIO(image_bytes)).convert('RGB')
54
-
55
  prompt_results = []
56
  if mode == 'best':
57
  prompt_result = ci.interrogate(image, max_flavors=int(best_max_flavors))
@@ -68,6 +70,7 @@ def inference(input_image, mode, best_max_flavors):
68
 
69
 
70
 
 
71
  title = """
72
  <div style="text-align: center; max-width: 500px; margin: 0 auto;">
73
  <div
@@ -163,7 +166,7 @@ with gr.Blocks() as block:
163
  with gr.Column(elem_id="col-container"):
164
  gr.HTML(title)
165
 
166
- input_image = gr.Image(type="file", label="Upload Image")
167
  mode_input = gr.Radio (['classic', 'fast'], label='Select mode', value='fast')
168
  flavor_input = gr.Slider(minimum=2, maximum=24, step=2, value=4, label='best mode max flavors')
169
  submit_btn = gr.Button("Submit")
 
46
  ci = Interrogator(config)
47
 
48
  def inference(input_image, mode, best_max_flavors):
49
+ # Convert the PIL image to bytes
50
+ with io.BytesIO() as output:
51
+ input_image.save(output, format="JPEG")
52
+ image_bytes = output.getvalue()
53
 
54
  # Process the image and generate prompt results based on the selected mode
55
+ image = input_image.convert('RGB') # No need to convert, already in RGB
56
+
57
  prompt_results = []
58
  if mode == 'best':
59
  prompt_result = ci.interrogate(image, max_flavors=int(best_max_flavors))
 
70
 
71
 
72
 
73
+
74
  title = """
75
  <div style="text-align: center; max-width: 500px; margin: 0 auto;">
76
  <div
 
166
  with gr.Column(elem_id="col-container"):
167
  gr.HTML(title)
168
 
169
+ input_image = gr.Image(type="pil", label="Upload Image")
170
  mode_input = gr.Radio (['classic', 'fast'], label='Select mode', value='fast')
171
  flavor_input = gr.Slider(minimum=2, maximum=24, step=2, value=4, label='best mode max flavors')
172
  submit_btn = gr.Button("Submit")