ChristopherMarais commited on
Commit
36ea21a
·
1 Parent(s): 4a4ac05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -2,29 +2,18 @@ import gradio as gr
2
  from transformers import pipeline
3
 
4
  model = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
5
- def preprocess(image):
6
- # Define your preprocessing function here to break the uploaded image into multiple images
7
  # For example:
8
  images = [image.crop((0, 0, 100, 100)), image.crop((100, 100, 200, 200))]
9
- return images
10
-
11
- def predict(image):
12
- # Apply preprocessing function to uploaded image
13
- images = preprocess(image)
14
-
15
- # Apply model to all preprocessed images
16
- predictions = []
17
- for img in images:
18
- pred = model(img)
19
- predictions.append(pred[0])
20
-
21
- # Return predictions alongside images
22
  return images, predictions
23
 
 
24
  iface = gr.Interface(
25
  fn=predict,
26
  inputs=gr.inputs.Image(type='pil'),
27
- outputs=[gr.outputs.Image(type='pil', label='Image'), 'label']
28
  )
29
 
30
  # Launch Gradio app
 
2
  from transformers import pipeline
3
 
4
  model = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
5
+ def predict(image):
6
+ # Define your prediction function here
7
  # For example:
8
  images = [image.crop((0, 0, 100, 100)), image.crop((100, 100, 200, 200))]
9
+ predictions = ['cat', 'dog']
 
 
 
 
 
 
 
 
 
 
 
 
10
  return images, predictions
11
 
12
+ # Create Gradio interface
13
  iface = gr.Interface(
14
  fn=predict,
15
  inputs=gr.inputs.Image(type='pil'),
16
+ outputs=[gr.outputs.Image(type='pil', label='Images'), gr.outputs.Label(label='Predictions')]
17
  )
18
 
19
  # Launch Gradio app