radames's picture
Update index.html
a873681
<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>