File size: 1,546 Bytes
c6f1527
1812791
 
 
 
 
 
 
 
 
 
a873681
 
 
 
 
 
 
 
 
 
 
 
1812791
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<html>

  <head>
    <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
    <script type="module">
      import { env, pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
      env.allowLocalModels = false;
      let sentimentPipe = await pipeline('sentiment-analysis');
      globalThis.sentimentPipe = sentimentPipe;
    </script>
    <style>
      body {
       color: black;
       background-color: white;
      }
      @media (prefers-color-scheme: dark) {
           body {
               color: white;
               background-color: #0b0f19;
           }
      }
    </style>
  </head>

  <body>

    <gradio-lite>
      import gradio as gr
      
      js_predict = """
      async function(input){
        let result = await sentimentPipe(input);
        return result
      }"""
      def greet(name):
        return "Hello " + name + "!"

      with gr.Blocks() as demo:
        gr.Markdown("""## Sentiment Analysis with Transformer.js""")
        name = gr.Textbox(label="Input Text")
        output = gr.JSON(label="Output Result")
        greet_btn = gr.Button("Greet")
        greet_btn.click(None, inputs=name, outputs=output, api_name="greet", _js=js_predict)
        
        gr.Examples([
        "I don't feel well",
        "What a beautiful day"
        ], inputs=name, outputs=output)
      demo.launch(show_api=False)
    </gradio-lite>
  </body>

</html>