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