Data Science/Machine Learning
Gradio Example : Sentiment Analysis
DS-9VM
2023. 2. 24. 03:45
728x90
What Does Gradio Do?
One of the best ways to share your machine learning model, API, or data science workflow with others is to create an interactive app that allows your users or colleagues to try out the demo in their browsers.
Gradio allows you to build demos and share them, all in Python. And usually in just a few lines of code! So let's get started.
Install Gradio Package
!pip install gradio
!pip install transformers
Sentiment Analysis
text를 입력하면 감정(긍정/부정)을 평가하는 Apps
(Google Collab에서 테스트 가능함.)
import gradio as gr
import transformers
# Load the pre-trained sentiment analysis model
model = transformers.pipeline("sentiment-analysis")
# Define the Gradio interface
def sentiment_analysis(text):
result = model(text)[0]
label = result["label"]
score = result["score"]
return f"{label} with confidence score {score:.2f}"
iface = gr.Interface(fn=sentiment_analysis,
inputs=gr.inputs.Textbox(lines=5, label="Input text"),
outputs="text",
title="Sentiment Analysis")
# Launch the Gradio interface
iface.launch()
실행결과
Reference :
- Gradio Demos : https://gradio.app/demos/
- Gradio Documents : https://gradio.app/docs/
728x90