| import gradio as gr |
| from gradio_client import Client |
| import os |
|
|
| |
| HF_SPACE_ID = "YOUR_USERNAME/Arch" |
|
|
| def inspect_part_remote(image, threshold): |
| """ |
| Client function to call the Hugging Face Space |
| """ |
| if image is None: |
| return None, "Please provide an image" |
| |
| try: |
| |
| client = Client(HF_SPACE_ID) |
| |
| |
| result = client.predict( |
| image=image, |
| threshold=threshold, |
| api_name="/detect" |
| ) |
| |
| |
| return result[1], result[0] |
| except Exception as e: |
| return None, f"Error: {str(e)}" |
|
|
| |
| with gr.Blocks(title="HF Model Client") as demo: |
| gr.Markdown(f"# 🔗 TMTL Hugging Face Connector\nConnecting to: `{HF_SPACE_ID}`") |
| |
| with gr.Row(): |
| with gr.Column(): |
| img_input = gr.Image(type="pil") |
| threshold = gr.Slider(0.5, 0.99, value=0.7, label="Threshold") |
| btn = gr.Button("Analyze Remote") |
| with gr.Column(): |
| label_output = gr.Label(label="Matched Part") |
| text_output = gr.Markdown() |
| |
| btn.click( |
| fn=inspect_part_remote, |
| inputs=[img_input, threshold], |
| outputs=[label_output, text_output] |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|