36 lines
969 B
Python
36 lines
969 B
Python
import gradio as gr
|
|
from transformers import pipeline
|
|
|
|
from gradio.themes.utils import sizes
|
|
|
|
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
|
block_label_text_color = '#4D63FF',
|
|
block_title_text_color = '#4D63FF',
|
|
button_primary_text_color = '#4D63FF',
|
|
button_primary_background_fill='#FFFFFF',
|
|
button_primary_border_color='#4D63FF',
|
|
button_primary_background_fill_hover='#EDEFFF',
|
|
)
|
|
|
|
|
|
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
|
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
|
|
|
def sentiment_analysis(text):
|
|
results = sentiment_task(text)
|
|
|
|
return results
|
|
|
|
demo = gr.Interface(fn=sentiment_analysis,
|
|
inputs='text',
|
|
outputs='text',
|
|
title = "文本情感分析",
|
|
theme=theme
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
demo.queue(concurrency_count=3)
|
|
demo.launch()
|
|
|