Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ 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 |
|
@@ -25,9 +26,16 @@ def predict(inputs, top_p, temperature, openai_api_key):
|
|
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>")
|
@@ -37,12 +45,14 @@ with gr.Blocks() as demo:
|
|
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, temperature, openai_api_key], outputs=output)
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
[
|
46 |
-
|
|
|
|
|
47 |
|
48 |
demo.launch()
|
|
|
4 |
|
5 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
6 |
|
7 |
+
# ์คํฌ๋ฆฝํธ ์์ฑ ํจ์
|
8 |
def predict(inputs, top_p, temperature, openai_api_key):
|
9 |
narration_prompt = f"์๋์ฉ ์ ๋๋ฉ์ด์
๋์์์ ์ฌ์ฉํ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ๋ผ. ๋ฐ๋์ ํ๊ธ๋ก ์์ฑํ ๊ฒ. ์ผ์ฒด์ ์ง๋ฌธ์ด๋ ์ง์, ๋ฐฐ๊ฒฝ ์ค๋ช
๋ฑ์ ๋
ธ์ถ ํ๊ฑฐ๋ ์ถ๋ ฅํ์ง ๋ง๊ณ ๊ธฐ์น์ ๊ฒฐ์ ๊ตฌ์กฐ๋ก ๋ชจํ์ ์ด์ /์๊ธฐ/๋์ /๋ฌธ์ ํด๊ฒฐ/๊ตํ์ ํฌํจํ์ฌ ์์ํ ๋๋ ์ด์
๋ง 1์ค์ฉ ์ถ๋ ฅํ์ฌ ์ต๋ 10์ค ์ด๋ด๋ก ์ถ๋ ฅ. ์
๋ ฅ: '{inputs}'"
|
10 |
|
|
|
26 |
if response.status_code == 200:
|
27 |
response_data = response.json()
|
28 |
generated_text = response_data['choices'][0]['message']['content']
|
29 |
+
return generated_text.split('\n') # ์คํฌ๋ฆฝํธ๋ฅผ ์ค ๋จ์๋ก ๋ถ๋ฆฌํ์ฌ ๋ฐํ
|
30 |
else:
|
31 |
+
return ["Error: Unable to generate response."]
|
32 |
+
|
33 |
+
# ์ด๋ฏธ์ง ์์ฑ ํจ์
|
34 |
+
def generate_image(script_line, model_name="models/goofyai/3d_render_style_xl"):
|
35 |
+
# ์ด ํจ์ ๋ด์์๋ ์ด๋ฏธ์ง ์์ฑ ์์ฒญ์ ๋ณด๋ด๊ณ ๊ฒฐ๊ณผ๋ฅผ ์ฒ๋ฆฌํ๋ ์ฝ๋๋ฅผ ๊ตฌํํฉ๋๋ค.
|
36 |
+
# ์์๋ก๋ gr.Interface.load ๋๋ gr.load๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ ์ํฉ๋๋ค.
|
37 |
+
# ์ค์ ๊ตฌํ ์์๋ API ํธ์ถ ๋๋ Gradio์ ์ธ๋ถ ๋ชจ๋ธ ๋ก๋ฉ ๊ธฐ๋ฅ์ ๋ฐ๋ผ ์ ์ ํ ์์ ํด์ผ ํฉ๋๋ค.
|
38 |
+
pass # ์ฌ๊ธฐ์ ์ด๋ฏธ์ง ์์ฑ ์ฝ๋ ๊ตฌํ
|
39 |
|
40 |
with gr.Blocks() as demo:
|
41 |
gr.Markdown("<h1 align='center'>ํ ๋ฆฌ์ ๋ชจํ: 3D ์ ๋๋ฉ์ด์
์์ฑ๊ธฐ</h1>")
|
|
|
45 |
top_p = gr.Slider(minimum=0, maximum=1.0, value=1.0, step=0.05, label="Top-p (nucleus sampling)")
|
46 |
temperature = gr.Slider(minimum=0, maximum=5.0, value=1.0, step=0.1, label="Temperature")
|
47 |
output = gr.Textbox(label="Generated Script", readonly=True)
|
48 |
+
image_output = gr.Gallery(label="Generated Images") # ์์ฑ๋ ์ด๋ฏธ์ง๋ฅผ ํ์ํ ๊ฐค๋ฌ๋ฆฌ
|
49 |
submit_button = gr.Button("Generate")
|
|
|
50 |
|
51 |
+
def process_and_generate_images(inputs, top_p, temperature, openai_api_key):
|
52 |
+
scripts = predict(inputs, top_p, temperature, openai_api_key)
|
53 |
+
images = [generate_image(script) for script in scripts] # ๊ฐ ์คํฌ๋ฆฝํธ ์ค์ ๋ํ ์ด๋ฏธ์ง ์์ฑ
|
54 |
+
return scripts, images # ์คํฌ๋ฆฝํธ์ ์ด๋ฏธ์ง URL ๋ฐํ
|
55 |
+
|
56 |
+
submit_button.click(fn=process_and_generate_images, inputs=[inputs, top_p, temperature, openai_api_key], outputs=[output, image_output])
|
57 |
|
58 |
demo.launch()
|