Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| load_js1 = """ | |
| async () => { | |
| const script = document.createElement("script"); | |
| script.onload = () => console.log("module loaded") ; | |
| script.type="module"; | |
| script.src = "https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js"; | |
| document.head.appendChild(script) | |
| }""" | |
| load_js2 = """ | |
| function(text_input, url_params) { | |
| console.log(text_input, url_params); | |
| const params = new URLSearchParams(window.location.search); | |
| url_params = Object.fromEntries(params); | |
| return [text_input, url_params] | |
| } | |
| """ | |
| def predict(text, url_params): | |
| mod_url="" | |
| mod=gr.HTML("") | |
| out = None | |
| valid=gr.update(visible=False) | |
| try: | |
| mod_url = url_params.get('url') | |
| if mod_url != None: | |
| #print (mod_url) | |
| out = gr.HTML.update(f"""<div><h1>Loading model from:<br>{mod_url} </h1></div>""") | |
| valid=gr.update(visible=False) | |
| else: | |
| out=gr.HTML.update(f"""<div><h1>Enter Model URL</h1></div>""") | |
| valid=gr.update(visible=True) | |
| except Exception as e: | |
| out=gr.HTML.update(f"""<div><h1>Enter Model URL</h1></div>""") | |
| valid=gr.update(visible=True) | |
| return ["" + text + "", mod,out,mod_url,valid] | |
| def find_model(url): | |
| out = None | |
| mod=None | |
| if url != "" and url != None: | |
| try: | |
| mod = gr.HTML(f''' | |
| <div> | |
| <model-viewer src="{url}" camera-controls poster="https://cdn.glitch.global/fe6d4fc5-58dd-43de-a65d-7bd5b477e8e1/poster.webp?v=1696812691961" shadow-intensity="1"></model-viewer> | |
| </div> | |
| ''') | |
| except Exception as e: | |
| out = gr.HTML(f'''<div><h1>Could not find Model</h1><br><h3>System Message: {e}</div>''') | |
| else: | |
| out = gr.HTML(f'''<div><h1>Enter Model URL</h1></div>''') | |
| return mod,out | |
| with gr.Blocks(css="style.css") as app: | |
| markdown = gr.HTML("""""") | |
| with gr.Row(visible=False) as valid: | |
| inp = gr.Textbox(label="URL") | |
| go_btn=gr.Button("Load") | |
| out_html=gr.HTML('''''') | |
| ''' | |
| with gr.Tab("iFrame"): | |
| gr.HTML(""" | |
| <div> | |
| <iframe src="https://lumalabs.ai/embed/2b2112cd-9aa0-44f3-88b3-fde365066a3b?mode=sparkles&background=%23ffffff&color=%23000000&showTitle=true&loadBg=true&logoPosition=bottom-left&infoPosition=bottom-right&cinematicVideo=undefined&showMenu=false" width="100%" height="1000" frameborder="0" title="luma embed" style="border: none;"></iframe> | |
| </div> | |
| """) | |
| ''' | |
| with gr.Row(visible=False): | |
| text_input=gr.Textbox() | |
| text_output=gr.Textbox() | |
| url_params = gr.JSON({}, visible=True, label="") | |
| app.load(None,None,None,_js=load_js1) | |
| app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,out_html,markdown,inp,valid],_js=load_js2).then(find_model,inp,[out_html,markdown]) | |
| go_btn.click(find_model,inp,[out_html,markdown]) | |
| app.launch() | |