seawolf2357 commited on
Commit
a8c6d92
ยท
verified ยท
1 Parent(s): 2f76355

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
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
- examples = gr.Examples(examples=[
44
- ["์Šคํฌ๋ฆฝํŠธ: ํ† ๋ฆฌ๋Š” ๊ฒ€์€ ์ˆฒ์œผ๋กœ ๋ชจํ—˜์„ ๋– ๋‚ฌ๋‹ค."],
45
- ["์Šคํฌ๋ฆฝํŠธ: ํ† ๋ฆฌ๋Š” ๋ฐ”๋‹ค๋กœ ๋ชจํ—˜์„ ๋– ๋‚ฌ๋‹ค."]
46
- ], inputs=[inputs], fn=predict, outputs=output)
 
 
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()