Upload folder using huggingface_hub
Browse files- README.md +2 -8
- app.py +58 -0
- main.ipynb +0 -0
- real-fake-best.h5 +3 -0
- requirements.txt +5 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
title: RealVFake
|
3 |
-
emoji: 🔥
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: indigo
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.19.2
|
8 |
app_file: app.py
|
9 |
-
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: RealVFake
|
|
|
|
|
|
|
|
|
|
|
3 |
app_file: app.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 3.44.4
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
from io import BytesIO
|
6 |
+
from matplotlib import pyplot as plt
|
7 |
+
import numpy as np
|
8 |
+
import gradio as gr
|
9 |
+
import json
|
10 |
+
|
11 |
+
model = load_model('real-fake-best.h5')
|
12 |
+
|
13 |
+
def index(image_url):
|
14 |
+
response = requests.get(image_url)
|
15 |
+
img = Image.open(BytesIO(response.content))
|
16 |
+
img = np.array(img)
|
17 |
+
|
18 |
+
resize = tf.image.resize(img, (32, 32))
|
19 |
+
|
20 |
+
y_pred = model.predict(np.expand_dims(resize / 255, 0))
|
21 |
+
|
22 |
+
predictions = {"Fake": y_pred[0][0]*100, "Real": y_pred[0][1]*100}
|
23 |
+
|
24 |
+
print("Predictions:", y_pred)
|
25 |
+
predicted_class = np.argmax(y_pred)
|
26 |
+
print("Predicted Class:", predicted_class)
|
27 |
+
|
28 |
+
return json.dumps(predictions)
|
29 |
+
|
30 |
+
inputs_image_url = [
|
31 |
+
gr.Textbox(type="text", label="Image URL"),
|
32 |
+
]
|
33 |
+
|
34 |
+
outputs_result_dict = [
|
35 |
+
gr.Textbox(type="text", label="Result Dictionary"),
|
36 |
+
]
|
37 |
+
|
38 |
+
interface_image_url = gr.Interface(
|
39 |
+
fn=index,
|
40 |
+
inputs=inputs_image_url,
|
41 |
+
outputs=outputs_result_dict,
|
42 |
+
title="AI Image Detection",
|
43 |
+
cache_examples=False,
|
44 |
+
)
|
45 |
+
|
46 |
+
gr.TabbedInterface(
|
47 |
+
[interface_image_url],
|
48 |
+
tab_names=['Image inference']
|
49 |
+
).queue().launch()
|
50 |
+
|
51 |
+
|
52 |
+
# 0 -> AI
|
53 |
+
# 1 -> Real
|
54 |
+
|
55 |
+
# if y_pred > 0.5:
|
56 |
+
# print(f'REAL')
|
57 |
+
# else:
|
58 |
+
# print(f'AI')
|
main.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
real-fake-best.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:35ccc9c462511d4254e0ba3ac535c24d0079b06c618b0d34b0738d6cda86bcea
|
3 |
+
size 521584
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
opencv-python
|
3 |
+
matplotlib
|
4 |
+
numpy
|
5 |
+
gradio
|