oceankim commited on
Commit
e4be09f
β€’
1 Parent(s): de1aad1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -1,21 +1,26 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # 'sentiment-analysis' νŒŒμ΄ν”„λΌμΈ μ΄ˆκΈ°ν™”
5
- sentiment = pipeline('sentiment-analysis')
6
 
7
- # 감성 뢄석을 μˆ˜ν–‰ν•˜λŠ” ν•¨μˆ˜ μ •μ˜
8
  def get_sentiment(text):
9
- result = sentiment(text)
10
- return result[0]
11
 
12
- # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
13
- interface = gr.Interface(fn=get_sentiment,
14
- inputs=gr.inputs.Textbox(lines=2, placeholder="Type your text here..."),
15
- outputs='json',
16
- title="Sentiment Analysis",
17
- description="Enter text to analyze sentiment.")
 
 
 
18
 
19
- # Gradio μ•± μ‹€ν–‰
20
- if __name__ == "__main__":
21
- interface.launch()
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Initialize the Hugging Face sentiment-analysis pipeline
5
+ sentiment_model = pipeline("sentiment-analysis")
6
 
7
+ # Define the function that will use the model to predict sentiment
8
  def get_sentiment(text):
9
+ results = sentiment_model(text)
10
+ return results[0]["label"]
11
 
12
+ # Create the Gradio interface
13
+ interface = gr.Interface(
14
+ fn=get_sentiment,
15
+ inputs=gr.inputs.Textbox(placeholder="Type your text here..."),
16
+ outputs="text",
17
+ title="Sentiment Analysis",
18
+ description="Input a piece of text and click the button to analyze sentiment.",
19
+ theme="huggingface" # This applies Hugging Face theme to the interface
20
+ )
21
 
22
+ # The interface can be launched directly in Python
23
+ # interface.launch()
24
+
25
+ # To deploy to Hugging Face Spaces, save the interface as an object called 'demo'
26
+ demo = interface