Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
def classify_image(image):
|
4 |
+
# Preprocess the image
|
5 |
+
inputs = processor(images=image, return_tensors="pt")
|
6 |
+
|
7 |
+
# Predict
|
8 |
+
outputs = model(**inputs)
|
9 |
+
predictions = outputs.logits.softmax(dim=-1)
|
10 |
+
|
11 |
+
# Assuming your model returns two probabilities: [real, AI-generated]
|
12 |
+
probs = predictions.detach().numpy()[0]
|
13 |
+
labels = ['Real', 'AI-generated']
|
14 |
+
result = {labels[i]: probs[i] for i in range(len(labels))}
|
15 |
+
|
16 |
+
return result
|
17 |
+
|
18 |
+
# Create the Gradio interface
|
19 |
+
iface = gr.Interface(fn=classify_image, inputs=gr.inputs.Image(shape=(224, 224)), outputs=gr.outputs.Label(num_top_classes=2))
|
20 |
|
|
|
21 |
iface.launch()
|