Spaces:
Runtime error
Runtime error
Download app.py from LucaZampierin/Ceramic_inference: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/LucaZampierin/Ceramic_inference/resolve/main/app.py
- Command line
-
hf download hf://spaces/LucaZampierin/Ceramic_inference/app.py
-
curl -L -o app.py https://huggingface.co/spaces/LucaZampierin/Ceramic_inference/resolve/main/app.py
1.65 kB
| import os | |
| import gradio as gr | |
| read_key = os.environ.get('HF_TOKEN', None) | |
| image_retrieval = gr.load("LucaZampierin/ceramic_image_retrieval", hf_token=read_key, src="spaces") | |
| # def predict_function(t, d, o): | |
| # return image_retrieval((t, d, o), api_name="predict_function") | |
| # def process_image(query_image, mode, one_per_class, k=10): | |
| # return image_retrieval((query_image, mode, one_per_class, k), api_name="process_image") | |
| print(dir(image_retrieval)) | |
| def predict_function(t, d, o): | |
| # Call the predict function from the Gradio space | |
| return image_retrieval(t, d, o, api_name="predict-function") | |
| def process_image(query_image, mode, one_per_class, k=10): | |
| # Call the process image function from the Gradio space | |
| return image_retrieval(query_image, mode, one_per_class, k, api_name="process-image") | |
| with gr.Blocks() as demo: | |
| t = gr.Number(label="Thickness") | |
| d = gr.Number(label="Diameter") | |
| o = gr.Number(label="Open/Close") | |
| output = gr.Textbox(value="", label="Output") | |
| btn = gr.Button(value="Submit") | |
| btn.click(predict_function, inputs=[t, d, o], outputs=[output]) | |
| outputs = [[gr.Image(type='pil'), 'text'] for i in range(10)] | |
| outputs = [item for sublist in outputs for item in sublist] | |
| iface = gr.Interface( | |
| fn=process_image, | |
| inputs=[gr.ImageEditor(type='pil', transforms=["crop"], sources=['upload']), | |
| gr.Dropdown(["All", "I", "II", "III"], label="Class to show", info="Select the class to retrieve the images from"), | |
| gr.Checkbox(label="One per class")], | |
| outputs= outputs, | |
| live=True, | |
| ) | |
| demo.launch() |