universalml commited on
Commit
eb82f35
·
verified ·
1 Parent(s): b151fd6

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+
5
+ _MODEL_NAME = "lksef"
6
+ _HF_USER = "universalml"
7
+
8
+
9
+ def prediction_function(input_file):
10
+ # get user name of their hugging face
11
+ model_path = _HF_USER + "/" + _MODEL_NAME
12
+ # takes some time
13
+ classifier = pipeline("image-classification", model=model_path)
14
+
15
+ try:
16
+ result = classifier(input_file)
17
+ predictions = dict()
18
+ labels = []
19
+ for each_label in result:
20
+ predictions[each_label["label"]] = each_label["score"]
21
+ labels.append(each_label["label"])
22
+ result = predictions
23
+ except:
24
+ result = "no data provided!!"
25
+
26
+ return result
27
+
28
+
29
+ # change _MODEL_NAME parameter
30
+ def create_demo():
31
+ demo = gr.Interface(
32
+ fn=prediction_function,
33
+ inputs=gr.Image(type="pil"),
34
+ outputs=gr.Label(num_top_classes=3),
35
+ )
36
+ demo.launch()
37
+
38
+
39
+ create_demo()