ggureung commited on
Commit
fcf20d6
โ€ข
1 Parent(s): 7e98511

Create ggggggu

Browse files
Files changed (1) hide show
  1. ggggggu +26 -0
ggggggu ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ # OpenAI API ์ธ์ฆ ์ •๋ณด ์„ค์ •
5
+ api_key = "YOUR_OPENAI_API_KEY"
6
+ openai.api_key = api_key
7
+
8
+ # ๊ฐ์„ฑ ๋ถ„์„์„ ์œ„ํ•œ ํ•จ์ˆ˜
9
+ def analyze_sentiment(text):
10
+ # OpenAI API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…์ŠคํŠธ ๊ฐ์„ฑ ๋ถ„์„ ์ˆ˜ํ–‰
11
+ response = openai.Completion.create(
12
+ engine="text-davinci-002", # ๊ฐ์„ฑ ๋ถ„์„ ์—”์ง„ ์„ ํƒ
13
+ prompt=text,
14
+ temperature=0,
15
+ max_tokens=1
16
+ )
17
+ # ๊ฒฐ๊ณผ์—์„œ ๊ฐ์„ฑ ๋ ˆ์ด๋ธ” ์ถ”์ถœ
18
+ sentiment = response.choices[0].text.strip()
19
+ return sentiment
20
+
21
+ # Gradio๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›น ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
22
+ input_text = gr.inputs.Textbox(lines=5, label="Enter text for sentiment analysis")
23
+ output_text = gr.outputs.Textbox(label="Sentiment")
24
+
25
+ # Gradio UI ๊ตฌ์„ฑ
26
+ gr.Interface(analyze_sentiment, inputs=input_text, outputs=output_text).launch()