Spaces:
Running
Running
Create app.py
Browse files
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()
|