Spaces:
Runtime error
Runtime error
Switching to Gradio
Browse files- app.py +30 -38
- requirements.txt +0 -3
app.py
CHANGED
@@ -9,49 +9,41 @@ HuggingFace Spaces that:
|
|
9 |
# https://huggingface.co/docs/hub/en/spaces-sdks-streamlit
|
10 |
|
11 |
"""
|
12 |
-
|
13 |
-
import streamlit as st
|
14 |
-
from transformers import pipeline
|
15 |
from string import punctuation
|
16 |
-
import pandas as pd
|
17 |
-
# from huggingface_hub import InferenceClient
|
18 |
-
# client = InferenceClient(model="bdsl/HanmunRoBERTa")
|
19 |
-
|
20 |
-
# Load the pipeline with the HanmunRoBERTa model
|
21 |
-
model_pipeline = pipeline(task="text-classification", model="bdsl/HanmunRoBERTa")
|
22 |
|
23 |
-
# Streamlit app layout
|
24 |
title = "HanmunRoBERTa Century Classifier"
|
25 |
-
|
26 |
-
st.set_page_config(layout=layout, page_title=title, page_icon="π")
|
27 |
|
28 |
-
|
29 |
-
remove_punct = st.checkbox(label="Remove punctuation", value=True)
|
30 |
|
31 |
-
# Text area for user input
|
32 |
-
input_str = st.text_area("Input text", height=275)
|
33 |
|
34 |
-
|
35 |
-
if
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
characters_to_remove = "ββ‘()γγ:\"γΒ·, ?γ" + punctuation
|
38 |
translating = str.maketrans('', '', characters_to_remove)
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
9 |
# https://huggingface.co/docs/hub/en/spaces-sdks-streamlit
|
10 |
|
11 |
"""
|
12 |
+
import gradio as gr
|
|
|
|
|
13 |
from string import punctuation
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
15 |
title = "HanmunRoBERTa Century Classifier"
|
16 |
+
description = "Century classifier for classical Chinese and Korean texts"
|
|
|
17 |
|
18 |
+
hanmun_roberta = gr.Interface.load("bdsl/HanmunRoBERTa")
|
|
|
19 |
|
|
|
|
|
20 |
|
21 |
+
def inference(inputtext, model, strip_text):
|
22 |
+
if strip_text:
|
23 |
+
inputtext = strip_text(inputtext)
|
24 |
+
if model == "HanmunRoBERTa":
|
25 |
+
outlabel = hanmun_roberta(inputtext)
|
26 |
+
return outlabel
|
27 |
+
|
28 |
+
def strip_text(inputtext):
|
29 |
characters_to_remove = "ββ‘()γγ:\"γΒ·, ?γ" + punctuation
|
30 |
translating = str.maketrans('', '', characters_to_remove)
|
31 |
+
return inputtext.translate(translating)
|
32 |
+
|
33 |
+
gr.Interface(
|
34 |
+
inference,
|
35 |
+
[gr.inputs.Textbox(label="Input text",lines=10),
|
36 |
+
gr.inputs.Dropdown(choices=["HanmunRoBERTa"],
|
37 |
+
type="value",
|
38 |
+
default="HanmunRoBERTa",
|
39 |
+
label="model"),
|
40 |
+
gr.inputs.Checkbox(label="Remove punctuation", value=True),
|
41 |
+
],
|
42 |
+
[gr.outputs.Label(label="Output")],
|
43 |
+
examples=examples,
|
44 |
+
title=title,
|
45 |
+
description=description).launch(enable_queue=True)
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
requirements.txt
CHANGED
@@ -1,3 +0,0 @@
|
|
1 |
-
pandas==2.0.3
|
2 |
-
transformers[tf-cpu]
|
3 |
-
tensorflow
|
|
|
|
|
|
|
|