File size: 1,489 Bytes
19eed64
 
4812314
2a4b609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4812314
 
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
import gradio as gr

def initialize_interface():
    # Create a JavaScript snippet to detect the browser language
    detect_language_js = """
        var language = window.navigator.userLanguage || window.navigator.language;
        if (language === "zh-CN") {
            document.getElementById("container").innerHTML = `
                <div>
                    <label for="select_radio">你想使用哪种风格?</label>
                    <input type="radio" name="select_radio" value="卡通" checked> 卡通
                    <input type="radio" name="select_radio" value="风景"> 风景
                    <input type="radio" name="select_radio" value="肖像"> 肖像
                    <input type="radio" name="select_radio" value="生活"> 生活
                </div>
            `;
        } else {
            document.getElementById("container").innerHTML = `
                <div>
                    <label for="select_detail">Providing your cartoon photos, scenes and decorations can be redesigned for your cartoon characters.</label>
                    <input type="text" id="select_detail" value="" style="width: 300px;">
                </div>
            `;
        }
    """

    # Create a Gradio interface with a WebView output to display the JavaScript-generated interface
    interface = gr.Interface(fn=lambda: None, outputs="webview")
    interface.launch(share=True, update_fn=detect_language_js, webview_size=(600, 200))

initialize_interface()