javiercha commited on
Commit
ae0961d
·
verified ·
1 Parent(s): ab28271

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -2,10 +2,10 @@ import gradio as gr
2
  import os
3
  from transformers import pipeline
4
  import re
5
- import pandas as pd
6
 
7
  def preprocess_text(text):
8
- text = re.sub(r'[^\u4e00-\u9fff]', '', text)
9
  return text
10
 
11
  os.environ['HF_TOKEN'] = os.environ['Century_Test']
@@ -16,7 +16,21 @@ def predict_century(text):
16
  preprocessed_input = preprocess_text(text)
17
  result = nlp(preprocessed_input)
18
  result.sort(key=lambda x: x['score'], reverse=True)
19
- return {item['label']: item['score'] for item in result}
 
 
 
 
 
 
 
 
20
 
21
- iface = gr.Interface(fn=predict_century, inputs="text", outputs="json")
 
 
 
 
 
 
22
  iface.launch()
 
2
  import os
3
  from transformers import pipeline
4
  import re
5
+ import matplotlib.pyplot as plt
6
 
7
  def preprocess_text(text):
8
+ text = re.sub(r'[^\u4e00-\u9fff]', '', text)
9
  return text
10
 
11
  os.environ['HF_TOKEN'] = os.environ['Century_Test']
 
16
  preprocessed_input = preprocess_text(text)
17
  result = nlp(preprocessed_input)
18
  result.sort(key=lambda x: x['score'], reverse=True)
19
+
20
+ scores = {f"{i}th century": 0 for i in range(15, 20)}
21
+
22
+ for item in result:
23
+ scores[f"{item['label']}th century"] = item['score']
24
+
25
+ scores_text = "\n".join([f"{century}: {score*100:.2f}%" for century, score in scores.items()])
26
+
27
+ return preprocessed_input, scores_text
28
 
29
+ iface = gr.Interface(fn=predict_century,
30
+ inputs=gr.Textbox(label="Enter your text here:"),
31
+ outputs=[
32
+ gr.Textbox(label="Processed text (non-Sinitic and special characters removed):"),
33
+ "text"
34
+ ],
35
+ description="This Gradio web app uses the HanmunRoBERTa model \(March 2024 version\) to predict the century during which the inputted text was written. HanmunRoBERTa is a transformer model trained exclusively on literary Sinitic corpora written by Koreans before the 20th century. Please note that this is an early prototype optimised using the Veritable Records and the Diary of the Royal Secretariat data sets. The model is likely overfitted and requires fine-tuning and refinement.")
36
  iface.launch()