junggangosa / ggggggu
ggureung's picture
Create ggggggu
fcf20d6 verified
raw
history blame contribute delete
833 Bytes
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()