hyo37009 commited on
Commit
a988bac
1 Parent(s): c38a591
Files changed (2) hide show
  1. app.py +20 -2
  2. requirements.txt +8 -0
app.py CHANGED
@@ -1,7 +1,25 @@
1
  import gradio as gr
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  iface.launch()
 
1
  import gradio as gr
2
+ #
3
+ from transformers import SegformerFeatureExtractor, SegformerForSemanticSegmentation
4
+ from PIL import Image
5
+ import requests
6
+ #
7
 
8
+ feature_extractor = SegformerFeatureExtractor.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-640-1280")
9
+ model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-cityscapes-640-1280")
10
+
11
+
12
+ image = Image.open(requests.get(url, stream=True).raw)
13
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
14
+
15
+
16
+
17
+ inputs = feature_extractor(images=image, return_tensors="pt")
18
+ outputs = model(**inputs)
19
+ logits = outputs.logits # shape (batch_size, num_labels, height/4, width/4)
20
+
21
+ def greet():
22
+ return outputs
23
 
24
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
25
  iface.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ tensorflow
4
+ numpy
5
+ Image
6
+ matplotlib
7
+ PIL
8
+ requests