Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,41 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
# ์ค์ ์ ํ๋ฆฌ์ผ์ด์
์์๋ OpenAI API๋ ๋ค๋ฅธ ๋ชจ๋ธ์ ์ฌ์ฉํด ๊ตฌํํ ์ ์์ต๋๋ค.
|
5 |
-
def generate_script(inputs):
|
6 |
-
# ์์๋ฅผ ์ํ ๊ฐ์์ ์คํฌ๋ฆฝํธ ๋ฐํ
|
7 |
-
return "์ด๊ณณ์ ํ๋ คํ ๋์์ ์ ๊ฒฝ์
๋๋ค.\n์ ๋ฉ๋ฆฌ ๋น๋๋ ๋น๋ฉ๋ค ์ฌ์ด๋ก ํ ๋ฆฌ๊ฐ ๋ ์๊ฐ๋๋ค."
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
return gr.Interface.load("models/goofyai/3d_render_style_xl")
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
images = []
|
18 |
-
for line in script.split('\n'):
|
19 |
-
# ์ด๋ฏธ์ง ์์ฑ ๋ชจ๋ธ์ ๊ฐ ์คํฌ๋ฆฝํธ ์ค์ ์
๋ ฅ์ผ๋ก ์ ๊ณต
|
20 |
-
image = iface(line)
|
21 |
-
images.append(image)
|
22 |
-
return images
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
|
5 |
+
API_URL = "https://api.openai.com/v1/chat/completions"
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def predict(inputs, top_p, temperature, openai_api_key):
|
8 |
+
narration_prompt = f"์๋์ฉ ์ ๋๋ฉ์ด์
๋์์์ ์ฌ์ฉํ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ๋ผ. ๋ฐ๋์ ํ๊ธ๋ก ์์ฑํ ๊ฒ. ์ผ์ฒด์ ์ง๋ฌธ์ด๋ ์ง์, ๋ฐฐ๊ฒฝ ์ค๋ช
๋ฑ์ ๋
ธ์ถ ํ๊ฑฐ๋ ์ถ๋ ฅํ์ง ๋ง๊ณ ๊ธฐ์น์ ๊ฒฐ์ ๊ตฌ์กฐ๋ก ๋ชจํ์ ์ด์ /์๊ธฐ/๋์ /๋ฌธ์ ํด๊ฒฐ/๊ตํ์ ํฌํจํ์ฌ ์์ํ ๋๋ ์ด์
๋ง 1์ค์ฉ ์ถ๋ ฅํ์ฌ ์ต๋ 10์ค ์ด๋ด๋ก ์ถ๋ ฅ. ์
๋ ฅ: '{inputs}'"
|
|
|
9 |
|
10 |
+
headers = {
|
11 |
+
"Content-Type": "application/json",
|
12 |
+
"Authorization": f"Bearer {openai_api_key}"
|
13 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
payload = {
|
16 |
+
"model": "gpt-4-1106-preview",
|
17 |
+
"messages": [{"role": "system", "content": narration_prompt}],
|
18 |
+
"temperature": temperature,
|
19 |
+
"top_p": top_p,
|
20 |
+
"n": 1,
|
21 |
+
"max_tokens": 1000
|
22 |
+
}
|
23 |
|
24 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
25 |
+
if response.status_code == 200:
|
26 |
+
response_data = response.json()
|
27 |
+
generated_text = response_data['choices'][0]['message']['content']
|
28 |
+
return generated_text
|
29 |
+
else:
|
30 |
+
return "Error: Unable to generate response."
|
31 |
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("<h1 align='center'>ํ ๋ฆฌ์ ๋ชจํ: 3D ์ ๋๋ฉ์ด์
์์ฑ๊ธฐ</h1>")
|
34 |
+
with gr.Row():
|
35 |
+
openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here")
|
36 |
+
inputs = gr.Textbox(placeholder="์ฌ๊ธฐ์ ์
๋ ฅํ์ธ์.", label="์๋์ฉ ์ ๋๋ฉ์ด์
์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ๊ณ ์ถ์ ์ฃผ์ ์ด๋ ๋ฌธ์ฅ์ ์
๋ ฅํ์ธ์.")
|
37 |
+
top_p = gr.Slider(minimum=0, maximum=1.0, value=1.0, step=0.05, label="Top-p (nucleus sampling)")
|
38 |
+
temperature = gr.Slider(minimum=0, maximum=5.0, value=1.0, step=0.1, label="Temperature")
|
39 |
+
output = gr.Textbox(label="Generated Script", readonly=True)
|
40 |
+
submit_button = gr.Button("Generate")
|
41 |
+
submit_button.click(fn=predict, inputs=[inputs, top_p, temperatu
|