Spaces:
Runtime error
Runtime error
Adding application file
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# https://huggingface.co/blog/streamlit-spaces
|
2 |
+
# https://huggingface.co/docs/hub/en/spaces-sdks-streamlit
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
from transformers import pipeline
|
6 |
+
from string import punctuation
|
7 |
+
import pandas as pd
|
8 |
+
|
9 |
+
# Load the pipeline with your specific model
|
10 |
+
model_pipeline = pipeline(task="text-classification", model="bdsl/HanmunRoBERTa")
|
11 |
+
|
12 |
+
# Streamlit app layout
|
13 |
+
title = "HanmunRoBERTa Century Classifier"
|
14 |
+
st.title(title)
|
15 |
+
st.set_page_config(layout=layout, page_title=title, page_icon="π")
|
16 |
+
|
17 |
+
# Checkbox to remove punctuation
|
18 |
+
remove_punct = st.checkbox(label="Remove punctuation", value=True)
|
19 |
+
|
20 |
+
# Text area for user input
|
21 |
+
input_str = st.text_area("Input text", height=275)
|
22 |
+
|
23 |
+
|
24 |
+
# Remove punctuation if checkbox is selected
|
25 |
+
if remove_punct and input_text:
|
26 |
+
# Specify the characters to remove
|
27 |
+
characters_to_remove = "ββ‘()γγ:\"γΒ·, ?γ" + punctuation
|
28 |
+
translating = str.maketrans('', '', characters_to_remove)
|
29 |
+
input_str = input_str.translate(translating)
|
30 |
+
|
31 |
+
# Display the input text after processing
|
32 |
+
st.write("Processed input:", input_str)
|
33 |
+
|
34 |
+
# Predict and display the classification scores if input is provided
|
35 |
+
if st.button("Classify"):
|
36 |
+
if input_str:
|
37 |
+
predictions = model_pipeline(input_str)
|
38 |
+
|
39 |
+
# Prepare the data for plotting
|
40 |
+
labels = [prediction['label'] for prediction in predictions]
|
41 |
+
scores = [prediction['score'] for prediction in predictions]
|
42 |
+
data = pd.DataFrame({"Label": labels, "Score": scores})
|
43 |
+
|
44 |
+
# Displaying predictions as a bar chart
|
45 |
+
st.bar_chart(data.set_index('Label'))
|
46 |
+
else:
|
47 |
+
st.write("Please enter some text to classify.")
|