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()

 

실행결과

Sentiment Analysis Gradio Apps


Reference :


 

728x90
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기
반응형