Ashrafb commited on
Commit
b2fcee5
·
1 Parent(s): 767c4ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -36
app.py CHANGED
@@ -13,46 +13,31 @@ config.blip_num_beams = 64
13
 
14
  ci = Interrogator(config)
15
 
16
- def inference(input_images, mode, best_max_flavors):
17
- # Process each image in the list and generate prompt results
18
- prompt_results = []
19
- for image_bytes in input_images['data']:
20
- image = Image.open(io.BytesIO(image_bytes)).convert('RGB')
21
- if mode == 'best':
22
- prompt_result = ci.interrogate(image, max_flavors=int(best_max_flavors))
23
- elif mode == 'classic':
24
- prompt_result = ci.interrogate_classic(image)
25
- else:
26
- prompt_result = ci.interrogate_fast(image)
27
- prompt_results.append(prompt_result) # Append text prompt result
28
- return prompt_results
29
-
30
- # Function to convert image bytes to file format
31
- def convert_to_file(image_bytes):
32
- file_dict = {"filename": ["image.jpg"], "data": [image_bytes]}
33
- return file_dict
34
-
35
- # Function to handle image upload and conversion
36
- def handle_image_upload(image):
37
- image_bytes = image.read()
38
- file_dict = convert_to_file(image_bytes)
39
- return file_dict
40
 
41
  with gr.Blocks() as block:
42
  with gr.Column(elem_id="col-container"):
43
-
44
-
45
-
46
- input_image_upload = gr.Image(label="Upload Image") # Using gr.Image for image upload
47
- mode_input = gr.Radio (['classic', 'fast'], label='Select mode', value='fast')
48
- flavor_input = gr.Slider(minimum=2, maximum=24, step=2, value=4, label='best mode max flavors')
49
  submit_btn = gr.Button("Submit")
50
- output_text = gr.Textbox(label="Output", elem_id="output-txt") # Changed the variable name here
51
 
52
- def process_image(image):
53
- file_dict = handle_image_upload(image)
54
- output_text = gr.Textbox(label="Output", elem_id="output-txt") # Output Textbox
55
-
56
- submit_btn.click(fn=inference, inputs=[file_dict, mode_input, flavor_input], outputs=[output_text], api_name="clipi2")
57
 
 
 
58
  block.queue(max_size=32, concurrency_count=10).launch(show_api=False)
 
13
 
14
  ci = Interrogator(config)
15
 
16
+ def inference(input_image, mode, best_max_flavors):
17
+ image_bytes = input_image.read()
18
+ image = Image.open(io.BytesIO(image_bytes)).convert('RGB')
19
+
20
+ if mode == 'best':
21
+ prompt_result = ci.interrogate(image, max_flavors=int(best_max_flavors))
22
+ elif mode == 'classic':
23
+ prompt_result = ci.interrogate_classic(image)
24
+ else:
25
+ prompt_result = ci.interrogate_fast(image)
26
+
27
+ return prompt_result
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  with gr.Blocks() as block:
30
  with gr.Column(elem_id="col-container"):
31
+ input_image = gr.Image(label="Upload Image") # Using gr.Image for image upload
32
+ mode_input = gr.Radio(['classic', 'fast', 'best'], label='Select mode', default='fast')
33
+ flavor_input = gr.Slider(minimum=2, maximum=24, step=2, default=4, label='Best mode max flavors')
 
 
 
34
  submit_btn = gr.Button("Submit")
35
+ output_text = gr.Textbox(label="Output", elem_id="output-txt") # Output Textbox
36
 
37
+ def process_image():
38
+ prompt_result = inference(input_image, mode_input, flavor_input)
39
+ output_text = prompt_result
 
 
40
 
41
+ submit_btn.click(process_image)
42
+
43
  block.queue(max_size=32, concurrency_count=10).launch(show_api=False)