arch / app_huggingface.py
eho69's picture
Create app_huggingface.py
311b3f3 verified
import gradio as gr
from gradio_client import Client
import os
# Configuration
HF_SPACE_ID = "YOUR_USERNAME/Arch" # Update this with your actual Space ID
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:
# Initialize the client
client = Client(HF_SPACE_ID)
# Call the 'detect' endpoint
result = client.predict(
image=image,
threshold=threshold,
api_name="/detect"
)
# result[0] is the formatted text, result[1] is the matched label
return result[1], result[0]
except Exception as e:
return None, f"Error: {str(e)}"
# Standalone testing interface
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()