Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
model = load_model("large_model_3lakh_v1.h5")
|
| 7 |
+
|
| 8 |
+
title = '🧠 AI FORGED IMAGE DETECTOR'
|
| 9 |
+
|
| 10 |
+
description = 'THROUGH THIS APPLICATION YOU CAN INPUT AN IMAGE AND THE WEBSITE WILL TELL WHETHER THE IMAGE IS AI GENERATED OR NOT.'
|
| 11 |
+
list_num = [0, 1]
|
| 12 |
+
#0 is fake 1 is true
|
| 13 |
+
|
| 14 |
+
def closest(lst, K):
|
| 15 |
+
return lst[min(range(len(lst)), key=lambda i: abs(lst[i] - K))]
|
| 16 |
+
def hell(image):
|
| 17 |
+
pred = model.predict(np.expand_dims(image / 255, 0))
|
| 18 |
+
result = closest(list_num, pred[0])
|
| 19 |
+
if result == 0:
|
| 20 |
+
return "The image is generated by AI"
|
| 21 |
+
if result == 1:
|
| 22 |
+
return "The Image is not generated by AI"
|
| 23 |
+
|
| 24 |
+
demo = gr.Interface(fn=hell, inputs=[gr.Image(shape=(256,256))], outputs=["text"],
|
| 25 |
+
# Pass through title and description
|
| 26 |
+
title=title, description=description,
|
| 27 |
+
# Set theme and launch parameters
|
| 28 |
+
theme='finlaymacklon/boxy_violet')
|
| 29 |
+
|
| 30 |
+
demo.launch()
|