Rahatara commited on
Commit
404d2bc
·
verified ·
1 Parent(s): 52c4718

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -28,9 +28,8 @@ def generate_storyboard(scenario):
28
  return completion.choices[0].message.content
29
 
30
  # Interactive chatbot with streaming response
31
- def chatbot_stream(user_input):
32
- messages = [
33
- {"role": "system", "content": "You are an expert in storyboarding. Answer questions interactively."},
34
  {"role": "user", "content": user_input}
35
  ]
36
 
@@ -48,7 +47,7 @@ def chatbot_stream(user_input):
48
  for chunk in completion:
49
  text_chunk = chunk.choices[0].delta.content or ""
50
  response += text_chunk
51
- yield {"role": "assistant", "content": response}
52
 
53
  # Gradio UI with enhanced chat interface
54
  def ui():
@@ -69,12 +68,16 @@ def ui():
69
  quick_questions = ["How do I structure a storyboard?", "What makes a good visual scene?", "How to add depth to a story?"]
70
  with gr.Row():
71
  for question in quick_questions:
72
- gr.Button(question, variant="secondary").click(lambda q=question: chatbot_stream(q), inputs=None, outputs=chatbot)
 
 
 
 
73
 
74
  # Chatbot functionality
75
  send_button.click(
76
  fn=chatbot_stream,
77
- inputs=chat_input,
78
  outputs=chatbot,
79
  queue=True
80
  ).then(
 
28
  return completion.choices[0].message.content
29
 
30
  # Interactive chatbot with streaming response
31
+ def chatbot_stream(user_input, chat_history):
32
+ messages = chat_history + [
 
33
  {"role": "user", "content": user_input}
34
  ]
35
 
 
47
  for chunk in completion:
48
  text_chunk = chunk.choices[0].delta.content or ""
49
  response += text_chunk
50
+ yield chat_history + [{"role": "assistant", "content": response}]
51
 
52
  # Gradio UI with enhanced chat interface
53
  def ui():
 
68
  quick_questions = ["How do I structure a storyboard?", "What makes a good visual scene?", "How to add depth to a story?"]
69
  with gr.Row():
70
  for question in quick_questions:
71
+ gr.Button(question, variant="secondary").click(
72
+ fn=lambda q, h=[]: chatbot_stream(q, h),
73
+ inputs=[gr.State(), chatbot],
74
+ outputs=chatbot
75
+ )
76
 
77
  # Chatbot functionality
78
  send_button.click(
79
  fn=chatbot_stream,
80
+ inputs=[chat_input, chatbot],
81
  outputs=chatbot,
82
  queue=True
83
  ).then(