Spaces:
Runtime error
Runtime error
Commit
·
605c3c2
1
Parent(s):
d68a054
Update app.py
Browse files
app.py
CHANGED
|
@@ -243,7 +243,7 @@ class canny2image:
|
|
| 243 |
# need to explicitly call pipe.to("cuda").
|
| 244 |
self.pipe.enable_model_cpu_offload()
|
| 245 |
|
| 246 |
-
|
| 247 |
|
| 248 |
# Generator seed,
|
| 249 |
self.generator = torch.manual_seed(0)
|
|
@@ -289,9 +289,9 @@ class BLIPVQA:
|
|
| 289 |
return answer
|
| 290 |
|
| 291 |
class ConversationBot:
|
| 292 |
-
def __init__(self):
|
| 293 |
print("Initializing VisualChatGPT")
|
| 294 |
-
self.llm = OpenAI(temperature=0)
|
| 295 |
self.edit = ImageEditing(device="cuda")
|
| 296 |
self.i2t = ImageCaptioning(device="cuda")
|
| 297 |
self.t2i = T2I(device="cuda")
|
|
@@ -415,11 +415,21 @@ class ConversationBot:
|
|
| 415 |
return state, state, txt + ' ' + image_filename + ' '
|
| 416 |
|
| 417 |
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:
|
|
|
|
|
|
|
|
|
|
| 420 |
chatbot = gr.Chatbot(elem_id="chatbot", label="Visual ChatGPT")
|
| 421 |
state = gr.State([])
|
| 422 |
-
|
|
|
|
|
|
|
| 423 |
with gr.Column(scale=0.7):
|
| 424 |
txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter, or upload an image").style(container=False)
|
| 425 |
with gr.Column(scale=0.15, min_width=0):
|
|
@@ -427,6 +437,7 @@ with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:
|
|
| 427 |
with gr.Column(scale=0.15, min_width=0):
|
| 428 |
btn = gr.UploadButton("Upload", file_types=["image"])
|
| 429 |
|
|
|
|
| 430 |
txt.submit(bot.run_text, [txt, state], [chatbot, state])
|
| 431 |
txt.submit(lambda: "", None, txt)
|
| 432 |
btn.upload(bot.run_image, [btn, state, txt], [chatbot, state, txt])
|
|
|
|
| 243 |
# need to explicitly call pipe.to("cuda").
|
| 244 |
self.pipe.enable_model_cpu_offload()
|
| 245 |
|
| 246 |
+
self.pipe.enable_xformers_memory_efficient_attention()
|
| 247 |
|
| 248 |
# Generator seed,
|
| 249 |
self.generator = torch.manual_seed(0)
|
|
|
|
| 289 |
return answer
|
| 290 |
|
| 291 |
class ConversationBot:
|
| 292 |
+
def __init__(self, api_key):
|
| 293 |
print("Initializing VisualChatGPT")
|
| 294 |
+
self.llm = OpenAI(temperature=0, openai_api_key = api_key)
|
| 295 |
self.edit = ImageEditing(device="cuda")
|
| 296 |
self.i2t = ImageCaptioning(device="cuda")
|
| 297 |
self.t2i = T2I(device="cuda")
|
|
|
|
| 415 |
return state, state, txt + ' ' + image_filename + ' '
|
| 416 |
|
| 417 |
|
| 418 |
+
def init_conversation_bot(api_key):
|
| 419 |
+
bot = ConversationBot(api_key)
|
| 420 |
+
return bot,gr.update(visible = True)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
#bot = ConversationBot()
|
| 424 |
with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:
|
| 425 |
+
openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here")
|
| 426 |
+
|
| 427 |
+
|
| 428 |
chatbot = gr.Chatbot(elem_id="chatbot", label="Visual ChatGPT")
|
| 429 |
state = gr.State([])
|
| 430 |
+
bot = gr.State([])
|
| 431 |
+
|
| 432 |
+
with gr.Row(visible = False) as input_row:
|
| 433 |
with gr.Column(scale=0.7):
|
| 434 |
txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter, or upload an image").style(container=False)
|
| 435 |
with gr.Column(scale=0.15, min_width=0):
|
|
|
|
| 437 |
with gr.Column(scale=0.15, min_width=0):
|
| 438 |
btn = gr.UploadButton("Upload", file_types=["image"])
|
| 439 |
|
| 440 |
+
openai_api_key.submit(init_conversation_bot,[openai_api_key],[bot, input_row])
|
| 441 |
txt.submit(bot.run_text, [txt, state], [chatbot, state])
|
| 442 |
txt.submit(lambda: "", None, txt)
|
| 443 |
btn.upload(bot.run_image, [btn, state, txt], [chatbot, state, txt])
|