JUNGU commited on
Commit
a42f62d
ยท
1 Parent(s): 2d47d11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -15,12 +15,11 @@ current_image_url = ""
15
 
16
  def generate_image_url(keywords):
17
  return f"https://image.pollinations.ai/prompt/{quote(keywords)}"
18
-
19
- def next_chapter():
20
  global chapter_num, current_story, current_image_url
21
  current_image_url = generate_image_url(current_story) # ๋‹ค์Œ ์žฅ์˜ ์ด๋ฏธ์ง€ URL์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
22
  gr.Info(f'Chapter {chapter_num}๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค...')
23
- chapter_prompt = f"{story_intro}\n\n![Chapter {chapter_num} Image]({current_image_url})\n\nChapter {chapter_num} ๋‚ด์šฉ์„ ๋งŒ๋“ค์–ด์ค˜."
24
  chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo-16k", messages=[{"role": "user", "content": chapter_prompt}])
25
  current_story = chat_completion.choices[0].message.content
26
  chapter_num += 1
@@ -72,8 +71,9 @@ with gr.Blocks(css=css) as demo:
72
 
73
  submit_btn.click(fn=infer, inputs=[image_in, audience, keyword_in, protagonist_in],
74
  outputs=[chapter_story, chapter_image])
75
-
76
- next_chapter_btn.click(fn=next_chapter,
77
- outputs=[chapter_story, chapter_image])
 
78
 
79
  demo.queue(max_size=12).launch()
 
15
 
16
  def generate_image_url(keywords):
17
  return f"https://image.pollinations.ai/prompt/{quote(keywords)}"
18
+ def next_chapter(audience, keyword, protagonist):
 
19
  global chapter_num, current_story, current_image_url
20
  current_image_url = generate_image_url(current_story) # ๋‹ค์Œ ์žฅ์˜ ์ด๋ฏธ์ง€ URL์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
21
  gr.Info(f'Chapter {chapter_num}๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค...')
22
+ chapter_prompt = f"{story_intro}\n\nKeyword: {keyword}\nProtagonist: {protagonist}\n\n![Chapter {chapter_num} Image]({current_image_url})\n\nChapter {chapter_num} ๋‚ด์šฉ์„ ๋งŒ๋“ค์–ด์ค˜."
23
  chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo-16k", messages=[{"role": "user", "content": chapter_prompt}])
24
  current_story = chat_completion.choices[0].message.content
25
  chapter_num += 1
 
71
 
72
  submit_btn.click(fn=infer, inputs=[image_in, audience, keyword_in, protagonist_in],
73
  outputs=[chapter_story, chapter_image])
74
+ next_chapter_btn.click(fn=lambda: next_chapter(audience=audience.value, keyword=keyword_in.value, protagonist=protagonist_in.value),
75
+ outputs=[chapter_story, chapter_image])
76
+ # next_chapter_btn.click(fn=next_chapter,
77
+ # outputs=[chapter_story, chapter_image])
78
 
79
  demo.queue(max_size=12).launch()