| import os |
| import gradio as gr |
| from huggingface_hub import login |
| from huggingface_hub import snapshot_download |
| import numpy as np |
| import tensorflow as tf |
| import cv2 |
|
|
| def image_mod(image): |
| |
| |
| res = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA) |
| res = image.astype("float32") / 255.0 |
|
|
| |
| res = np.array([res]) |
|
|
| |
| result = 1.0 - model.predict(res)[0][0] |
|
|
| |
| return result |
|
|
| |
| login(token=os.environ['TOKEN_KESTREL_READ']) |
| model_path = snapshot_download(repo_id=os.environ['REPO_KESTREL_MODEL']) |
| model = tf.keras.models.load_model(model_path) |
|
|
| |
| input_image_component = gr.Image(image_mode="RGBA", type="numpy") |
| output_number_component = gr.Number() |
|
|
| |
| iface = gr.Interface( |
| fn=image_mod, |
| inputs=input_image_component, |
| outputs=output_number_component, |
| live=True, |
| title="", |
| description="", |
| article="" |
| ) |
|
|
| |
| iface.launch( |
| share=False, |
| auth=(os.environ['USER_KESTREL'], |
| os.environ['PASSWORD_KESTREL']) |
| ) |
|
|