File size: 2,981 Bytes
0319fb5
 
5a35e66
1b4032b
2381e8f
1b4032b
2381e8f
1b4032b
 
 
5a35e66
 
e5e2848
 
 
 
043a08d
e5e2848
0319fb5
e5e2848
 
b8198f0
45042a2
fe06229
9f8ae6f
45042a2
 
 
fe06229
ef7a625
9f8ae6f
45042a2
ef7a625
9f8ae6f
45042a2
ef7a625
9f8ae6f
71cb2be
e5e2848
a2fa543
fe9e0e3
5da8dfa
 
 
 
 
ef7a625
5da8dfa
 
d8196f1
5da8dfa
ef7a625
5da8dfa
ef7a625
5da8dfa
b2d17c4
 
7f7f590
ef7a625
da82e76
 
 
 
a2fa543
d16530a
 
 
686f16f
d16530a
 
a2fa543
e5e2848
 
 
 
 
 
 
ed2a203
9f8ae6f
5597d94
0319fb5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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()