Spaces:
No application file
No application file
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()
|