File size: 1,002 Bytes
e5673dc
 
 
 
 
 
 
ac0c654
 
 
e5673dc
ac0c654
 
 
e5673dc
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from transformers import pipeline

# Load the models using pipeline
image_model = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")

# Define the prediction function
def predict(image):
    result = image_model(image)
    print("Raw prediction result:", result)  # Debugging statement
        # Convert the result to the expected format
    output = {item['label']: item['score'] for item in result}
    print("Formatted prediction result:", output)  # Debugging statement
    return output
    except Exception as e:
        print("Error during prediction:", e)  # Debugging statement
        return {"error": str(e)}

# Create Gradio interface
with gr.Blocks() as iface:
    image_input = gr.Image(type="filepath", label="Upload Image File", visible=False)
    output = gr.Label()

    submit_button = gr.Button("Submit")
    submit_button.click(fn=predict, inputs=[audio_input, image_input, model_choice], outputs=output)
    
    iface.launch()