File size: 1,808 Bytes
9e6613e
 
 
 
 
 
 
1d9d1b1
 
 
a90b5f0
 
 
9e6613e
3033c0a
1d9d1b1
 
 
3033c0a
1d9d1b1
1d93a09
a686b95
1d9d1b1
1d93a09
 
 
 
1d9d1b1
1d93a09
 
a90b5f0
3033c0a
 
 
 
1d93a09
 
 
 
 
e827e9e
 
 
 
 
 
1d93a09
a686b95
e827e9e
3033c0a
 
e827e9e
 
 
 
3033c0a
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
"""
HuggingFace Spaces that:
- loads in HanmunRoBERTa model https://huggingface.co/bdsl/HanmunRoBERTa
- optionally strips text of punctuation and unwanted charactesr
- predicts century for the input text
- Visualizes prediction scores for each century

# https://huggingface.co/blog/streamlit-spaces
# https://huggingface.co/docs/hub/en/spaces-sdks-streamlit

# https://www.gradio.app/docs/interface
# https://huggingface.co/spaces/docs-demos/roberta-base/blob/main/app.py

"""
import gradio as gr
from string import punctuation

title = "HanmunRoBERTa Century Classifier"
description = "Century classifier for classical Chinese and Korean texts"

# Load the HanmunRoBERTa model
hanmun_roberta = gr.load("huggingface/bdsl/HanmunRoBERTa")

def strip_text(inputtext):
    characters_to_remove = "β—‹β–‘()〔〕:\"。·, ?ㆍ" + punctuation
    translating = str.maketrans('', '', characters_to_remove)
    return inputtext.translate(translating)

def inference(inputtext, model, strip_text_flag):
    if strip_text_flag:
        inputtext = strip_text(inputtext)
    if model == "HanmunRoBERTa":
        outlabel = hanmun_roberta(inputtext)
    return outlabel

# Define some example inputs for your interface
examples = [["Example text 1", "HanmunRoBERTa", True],
            ["Example text 2", "HanmunRoBERTa", True]]

# Set up the Gradio interface
gr.Interface(
    inference, 
    [gr.inputs.Textbox(label="Input text", lines=10),
     gr.inputs.Dropdown(choices=["HanmunRoBERTa"], 
                        type="value", 
                        default="HanmunRoBERTa", 
                        label="Model"),
     gr.inputs.Checkbox(label="Remove punctuation")], 
    [gr.outputs.Label(label="Output")],
    examples=examples,
    title=title,
    description=description).launch(enable_queue=True)