mischeiwiller commited on
Commit
a96ede8
1 Parent(s): 6388a95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -1,15 +1,32 @@
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.Label(num_top_classes=2),
 
14
  title="Hot Dog? Or Not?",
15
- ).launch()
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import numpy as np
4
 
5
+ # Initialize the pipeline
6
+ classifier = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
7
 
8
  def predict(image):
9
+ # Check if the input is a file path or numpy array
10
+ if isinstance(image, str):
11
+ # If it's a file path, pass it directly to the pipeline
12
+ predictions = classifier(image)
13
+ else:
14
+ # If it's a numpy array, we need to convert it to PIL Image
15
+ from PIL import Image
16
+ image = Image.fromarray(image.astype('uint8'), 'RGB')
17
+ predictions = classifier(image)
18
+
19
+ # Convert predictions to the format expected by Gradio
20
+ return {p["label"]: float(p["score"]) for p in predictions}
21
 
22
+ # Create the Gradio interface
23
+ iface = gr.Interface(
24
+ fn=predict,
25
+ inputs=gr.Image(label="Upload hot dog candidate"),
26
+ outputs=gr.Label(num_top_classes=2),
27
  title="Hot Dog? Or Not?",
28
+ description="Upload an image to see if it's a hot dog or not!",
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ iface.launch()