Views
No views yet
1import tensorflow as tf
2import numpy as np
3from PIL import Image
4from huggingface_hub import hf_hub_download
5
6# Descargar modelo
7model_path = hf_hub_download(
8 repo_id="juandaram/deepfake-detector",
9 filename="model.tflite"
10)
11
12# Cargar modelo
13interpreter = tf.lite.Interpreter(model_path=model_path)
14interpreter.allocate_tensors()
15
16# Preparar imagen
17image = Image.open("tu_imagen.jpg").convert('RGB')
18image = image.resize((128, 128))
19img_array = np.array(image, dtype=np.float32) / 255.0
20img_batch = np.expand_dims(img_array, axis=0)
21
22# Predecir
23input_details = interpreter.get_input_details()
24output_details = interpreter.get_output_details()
25interpreter.set_tensor(input_details[0]['index'], img_batch)
26interpreter.invoke()
27output = interpreter.get_tensor(output_details[0]['index'])
28
29prediction = "REAL" if output[0][0] > 0.5 else "FAKE"
30confidence = output[0][0] if output[0][0] > 0.5 else (1 - output[0][0])
31
32print(f"Prediction: {prediction}")
33print(f"Confidence: {confidence:.3f}")1import tensorflow as tf
2from huggingface_hub import snapshot_download
3
4# Descargar modelo completo
5model_dir = snapshot_download(repo_id="juandaram/deepfake-detector")
6
7# Cargar modelo
8model = tf.saved_model.load(f"{model_dir}/saved_model")
9infer = model.signatures['serving_default']
10
11# Usar igual que arriba...