ChristopherMarais commited on
Commit
4a4ac05
·
1 Parent(s): 498c472

test bingcaht recomendation

Browse files
Files changed (1) hide show
  1. app.py +37 -10
app.py CHANGED
@@ -1,18 +1,45 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
 
 
 
 
5
 
6
  def predict(image):
7
- predictions = pipeline(image)
8
- return {p["label"]: p["score"] for p in predictions}
9
-
10
- gr.Interface(
11
- predict,
12
- inputs=gr.inputs.Image(label="Upload hot dog candidate", type="filepath"),
13
- outputs=[gr.outputs.Image(type='pil', label='Image'), gr.outputs.Label(num_top_classes=2)], # gr.outputs.Label(num_top_classes=2),
14
- title="Hot Dog? Or Not?",
15
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # def greet(name):
18
  # return "Hello " + name + "!!"
 
1
  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
31
+ iface.launch()
32
+
33
+ # def predict(image):
34
+ # predictions = model(image)
35
+ # return {p["label"]: p["score"] for p in predictions}
36
+
37
+ # gr.Interface(
38
+ # predict,
39
+ # inputs=gr.inputs.Image(label="Upload hot dog candidate", type="filepath"),
40
+ # outputs=[gr.outputs.Image(type='pil', label='Image'), gr.outputs.Label(num_top_classes=2)], # gr.outputs.Label(num_top_classes=2),
41
+ # title="Hot Dog? Or Not?",
42
+ # ).launch()
43
 
44
  # def greet(name):
45
  # return "Hello " + name + "!!"