|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
import os |
|
|
|
|
|
api_token = os.getenv("HUGGINGFACE_API_TOKEN") |
|
|
|
|
|
client = InferenceClient( |
|
model="SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net", |
|
token=api_token |
|
) |
|
|
|
def predict(image): |
|
""" |
|
Process the uploaded image and return the segmentation result. |
|
|
|
Args: |
|
image: PIL Image object from Gradio input |
|
|
|
Returns: |
|
The segmentation result (assumed to be an image) or an error message |
|
""" |
|
try: |
|
|
|
|
|
result = client.post(data={"inputs": image}) |
|
|
|
|
|
return result |
|
except Exception as e: |
|
return f"Error: {str(e)}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(type="pil", label="Upload Panoramic X-ray Image"), |
|
outputs=gr.Image(type="pil", label="Segmentation Result"), |
|
title="Teeth Segmentation in Panoramic X-rays", |
|
description="Upload an X-ray image to see the segmented teeth." |
|
) |
|
|
|
|
|
iface.launch() |