File size: 833 Bytes
fcf20d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import openai
import gradio as gr

# OpenAI API ์ธ์ฆ ์ •๋ณด ์„ค์ •
api_key = "YOUR_OPENAI_API_KEY"
openai.api_key = api_key

# ๊ฐ์„ฑ ๋ถ„์„์„ ์œ„ํ•œ ํ•จ์ˆ˜
def analyze_sentiment(text):
    # OpenAI API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…์ŠคํŠธ ๊ฐ์„ฑ ๋ถ„์„ ์ˆ˜ํ–‰
    response = openai.Completion.create(
        engine="text-davinci-002",  # ๊ฐ์„ฑ ๋ถ„์„ ์—”์ง„ ์„ ํƒ
        prompt=text,
        temperature=0,
        max_tokens=1
    )
    # ๊ฒฐ๊ณผ์—์„œ ๊ฐ์„ฑ ๋ ˆ์ด๋ธ” ์ถ”์ถœ
    sentiment = response.choices[0].text.strip()
    return sentiment

# Gradio๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›น ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
input_text = gr.inputs.Textbox(lines=5, label="Enter text for sentiment analysis")
output_text = gr.outputs.Textbox(label="Sentiment")

# Gradio UI ๊ตฌ์„ฑ
gr.Interface(analyze_sentiment, inputs=input_text, outputs=output_text).launch()