yuragoithf commited on
Commit
3fd1af3
·
1 Parent(s): 03e9d8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -1,16 +1,36 @@
 
1
  import requests
2
- import os
 
3
 
4
- WD = os.getcwd()
5
- print(WD)
6
 
7
  API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-panoptic"
8
  headers = {"Authorization": "Bearer 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"}
9
 
10
- def query(filename):
11
- with open(filename.name, "rb") as f:
 
 
 
 
 
 
12
  data = f.read()
13
  response = requests.post(API_URL, headers=headers, data=data)
14
  return response.json()
15
 
16
- output = query("04_deer.jpg")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  import requests
3
+ from PIL import Image
4
+
5
 
 
 
6
 
7
  API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-panoptic"
8
  headers = {"Authorization": "Bearer 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"}
9
 
10
+
11
+ inputs = gr.inputs.Image(type="pil", label="Upload an image")
12
+ # output = query("cats.jpg")
13
+
14
+
15
+ # Perform image segmentation for multy class output
16
+ def query(inputs):
17
+ with open(inputs, "rb") as f:
18
  data = f.read()
19
  response = requests.post(API_URL, headers=headers, data=data)
20
  return response.json()
21
 
22
+
23
+ inputs = gr.inputs.Image(type="pil", label="Upload an image")
24
+ # outputs = gr.outputs.HTML() #uncomment for single class output
25
+ #outputs = query(inputs)
26
+
27
+ title = "<h1 style='text-align: center;'>Image Segmentation</h1>"
28
+ description = "Upload an image and get the segmentation result."
29
+
30
+ gr.Interface(fn=classify_image,
31
+ inputs=inputs,
32
+ outputs=query(inputs.get_name()),
33
+ title=title,
34
+ examples=[["00_plane.jpg"], ["01_car.jpg"], ["02_bird.jpg"], ["03_cat.jpg"], ["04_deer.jpg"]],
35
+ description=description,
36
+ enable_queue=True).launch()