Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,30 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
demo = gr.Interface(
|
| 7 |
-
fn=
|
| 8 |
-
inputs="
|
| 9 |
-
outputs="
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# โ
OpenAI ํค ์ค์ (Hugging Face์์ Secret์ผ๋ก ์ค์ ํด๋ OK)
|
| 6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
+
|
| 8 |
+
def generate_article(title):
|
| 9 |
+
prompt = f"์ฃผ์ : {title}\n\n์ด ์ฃผ์ ์ ๋ํด 3~5๋ฌธ๋จ ์ ๋์ ์ฝํ
์ธ ์ด์์ ์์ฑํด์ค:"
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
response = openai.ChatCompletion.create(
|
| 13 |
+
model="gpt-3.5-turbo",
|
| 14 |
+
messages=[
|
| 15 |
+
{"role": "user", "content": prompt}
|
| 16 |
+
],
|
| 17 |
+
max_tokens=500
|
| 18 |
+
)
|
| 19 |
+
return response['choices'][0]['message']['content']
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"[์๋ฌ] {str(e)}"
|
| 22 |
|
| 23 |
demo = gr.Interface(
|
| 24 |
+
fn=generate_article,
|
| 25 |
+
inputs=gr.Textbox(label="์ฝํ
์ธ ์ ๋ชฉ"),
|
| 26 |
+
outputs=gr.Textbox(label="์์ฑ๋ ์ด์", lines=10),
|
| 27 |
+
title="GPT ์ฝํ
์ธ ์ด์ ์์ฑ๊ธฐ"
|
| 28 |
)
|
| 29 |
|
| 30 |
+
demo.launch()
|