Spaces:
Running
Running
leadingbridge
commited on
Commit
•
8886fb4
1
Parent(s):
cb652c0
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,24 @@
|
|
1 |
-
from transformers import BertTokenizerFast,TFBertForSequenceClassification,TextClassificationPipeline
|
2 |
import numpy as np
|
3 |
import tensorflow as tf
|
4 |
import gradio as gr
|
5 |
import openai
|
6 |
import os
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# Sentiment Analysis Pre-Trained Model
|
9 |
model_path = "leadingbridge/sentiment-analysis"
|
10 |
tokenizer = BertTokenizerFast.from_pretrained(model_path)
|
@@ -116,6 +130,13 @@ with gr.Blocks() as demo:
|
|
116 |
proceed_button = gr.Button("Translate")
|
117 |
proceed_button.click(fn=openai_translation_ce, inputs=inputs, outputs=outputs)
|
118 |
gr.Markdown("This model translate a Chinese sentence to English using the OpenAI engine. Enter a Chinese short sentence in the input box and click the 'Translate' button to get the translation result in English.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
gr.Markdown('''
|
120 |
We are happy to share with you some Chinese language models that we've made using NLP. When we looked online, we noticed that there weren't many resources available for Chinese NLP, so we hope that our models can be useful to you.
|
121 |
We want to mention that these models aren't perfect and there is still room for improvement. Because of limited resources, there might be some mistakes or limitations in the models.
|
|
|
1 |
+
from transformers import BertTokenizerFast,TFBertForSequenceClassification,TextClassificationPipeline, AutoTokenizer, T5ForConditionalGeneration
|
2 |
import numpy as np
|
3 |
import tensorflow as tf
|
4 |
import gradio as gr
|
5 |
import openai
|
6 |
import os
|
7 |
|
8 |
+
#Summarization Fine Tune Model
|
9 |
+
|
10 |
+
model_path = "leadingbridge/summarization"
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
12 |
+
model = T5ForConditionalGeneration.from_pretrained(model_path)
|
13 |
+
def summarize_text(text):
|
14 |
+
# Tokenize the input text
|
15 |
+
inputs = tokenizer.encode(text, return_tensors="pt")
|
16 |
+
# Generate the summary
|
17 |
+
summary_ids = model.generate(inputs)
|
18 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
19 |
+
# Return the summary
|
20 |
+
return summary
|
21 |
+
|
22 |
# Sentiment Analysis Pre-Trained Model
|
23 |
model_path = "leadingbridge/sentiment-analysis"
|
24 |
tokenizer = BertTokenizerFast.from_pretrained(model_path)
|
|
|
130 |
proceed_button = gr.Button("Translate")
|
131 |
proceed_button.click(fn=openai_translation_ce, inputs=inputs, outputs=outputs)
|
132 |
gr.Markdown("This model translate a Chinese sentence to English using the OpenAI engine. Enter a Chinese short sentence in the input box and click the 'Translate' button to get the translation result in English.")
|
133 |
+
with gr.Tab("📑Text Summarization"):
|
134 |
+
gr.Markdown("""<h4><center>📑Text Summarization</center></h4>""")
|
135 |
+
inputs = gr.Textbox(placeholder="Enter a Chinese text to summarize here.",lines=3)
|
136 |
+
outputs = gr.Textbox(label="Summary")
|
137 |
+
proceed_button = gr.Button("Summarize")
|
138 |
+
proceed_button.click(fn=summarize_text, inputs=inputs, outputs=outputs)
|
139 |
+
gr.Markdown("This model summarizes Chinese text using the MT5 language model. Enter a Chinese text in the input box and click the 'Summarize' button to get the summary.")
|
140 |
gr.Markdown('''
|
141 |
We are happy to share with you some Chinese language models that we've made using NLP. When we looked online, we noticed that there weren't many resources available for Chinese NLP, so we hope that our models can be useful to you.
|
142 |
We want to mention that these models aren't perfect and there is still room for improvement. Because of limited resources, there might be some mistakes or limitations in the models.
|