Heem2 commited on
Commit
724e7fa
·
verified ·
1 Parent(s): 48b8f28

Create app.py

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
+ modelName = "AI-vs-Real-Image-Detection"
6
+ hfUser = "Heem2"
7
+
8
+
9
+ def prediction_function(inputFile):
10
+ # get user name of their hugging face
11
+ modelPath = hfUser + "/" + modelName
12
+ # takes some time
13
+ classifier = pipeline("image-classification", model=modelPath)
14
+
15
+ try:
16
+ result = classifier(inputFile)
17
+ predictions = dict()
18
+ labels = []
19
+ for eachLabel in result:
20
+ predictions[eachLabel["label"]] = eachLabel["score"]
21
+ labels.append(eachLabel["label"])
22
+ result = predictions
23
+ except:
24
+ result = "no data provided!!"
25
+
26
+ return result
27
+
28
+
29
+ # change modelName 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=4),
35
+ )
36
+ demo.launch(auth=("admin", "Gr@ce"))
37
+
38
+
39
+ create_demo()