CoolFace
Apppublic

RamAnanth1/3D-Arena-Router

sourceHugging Faceupdated 3y agoView on Hugging Face
2likes
app.py66 linesDownload Raw Back to root
1#!/usr/bin/env python2 3import gradio as gr4import PIL.Image5import os6from gradio_client import Client, file7 8lgm_mini_client = Client("dylanebert/LGM-mini")9triposr_client = Client("stabilityai/TripoSR")10crm_client = Client("Zhengyi/CRM")11 12def run(image, model_name):13    file_path = "temp.png"14    image.save(file_path)15    16    if model_name=='lgm-mini':17      result = lgm_mini_client.predict(18      file_path,	# filepath  in 'image' Image component19      api_name="/run"20      )21      output = result22    23    elif model_name=='triposr':24        25        process_result = triposr_client.predict(26      file_path,	# filepath  in 'Input Image' Image component27      True,	# bool  in 'Remove Background' Checkbox component28      0.85,	# float (numeric value between 0.5 and 1.0) in 'Foreground Ratio' Slider component29      api_name="/preprocess")30        31        result = triposr_client.predict(32		process_result,	# filepath  in 'Processed Image' Image component33		256,	# float (numeric value between 32 and 320) in 'Marching Cubes Resolution' Slider component34		api_name="/generate")35 36        output = result[0]37 38    elif model_name=='crm':39        preprocess_result = crm_client.predict(40		file(file_path),	# filepath in 'Image input' Image component41		"Auto Remove background",	# Literal['Alpha as mask', 'Auto Remove background'] in 'backgroud choice' Radio component42		1,	# float (numeric value between 0.5 and 1.0) in 'Foreground Ratio' Slider component43		"#7F7F7F",	# str in 'Background Color' Colorpicker component44		api_name="/preprocess_image"45        )46 47        result = crm_client.predict(48    		file(preprocess_result), # filepath in 'Processed Image' Image component49    		1234,	# float in 'seed' Number component50    		5.5,	# float in 'guidance_scale' Number component51    		30,	# float in 'sample steps' Number component52    		api_name="/gen_image"53        )54        output = result[2]55    return output56 57 58demo = gr.Interface(59    fn=run,60    inputs=[gr.Image(type="pil"),gr.Textbox(label="Model Name")],61    outputs=gr.Model3D(label="3D Model"),62    api_name="synthesize",63    description="Router for the [3D Arena space](https://huggingface.co/spaces/RamAnanth1/3D-Arena) that does most of the generation"64)65 66demo.launch()