File size: 796 Bytes
007d820
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

from transformers.tools.text_classification import TextClassificationTool

classifier = TextClassificationTool()
labels = ["Star Wars", "Star Trek", "MCU", "LOTR", "Babylon 5", "DC Comics"]

iface = gr.Interface(
    fn=lambda s: classifier(s, labels=labels),
    inputs="text",
    outputs="text")
with gr.Blocks() as app:
    story=gr.TextArea(
        label='Story',
        placeholder='The space pirate drew his trusty blaster. This might be his last night in Mos Eisley')
    output=gr.Textbox(label='Fandom')
    note=gr.Markdown(f"I know {', '.join(labels)}")
    button = gr.Button('Classify')
    button.click(
        fn=lambda s: classifier(s, labels=labels),
        inputs=story,
        outputs=output,
        api_name="fandom")
                 
app.launch()