Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,8 @@ from threading import Thread
|
|
3 |
from typing import Dict, List
|
4 |
|
5 |
import gradio as gr
|
6 |
-
|
|
|
7 |
import torch
|
8 |
from PIL import Image
|
9 |
from transformers import (
|
@@ -70,8 +71,8 @@ def process_chat_history(history: List) -> tuple[List[Dict], List[Image.Image]]:
|
|
70 |
return messages, images
|
71 |
|
72 |
|
73 |
-
@spaces.GPU
|
74 |
-
def bot_streaming(message: Dict, history: List, max_new_tokens: int = 250)
|
75 |
"""
|
76 |
Generate streaming responses for the chatbot.
|
77 |
|
@@ -129,7 +130,7 @@ def bot_streaming(message: Dict, history: List, max_new_tokens: int = 250) -> st
|
|
129 |
|
130 |
demo = gr.ChatInterface(
|
131 |
fn=bot_streaming,
|
132 |
-
textbox=gr.MultimodalTextbox(),
|
133 |
additional_inputs=[
|
134 |
gr.Slider(
|
135 |
minimum=10,
|
@@ -139,10 +140,27 @@ demo = gr.ChatInterface(
|
|
139 |
label="Maximum number of new tokens to generate",
|
140 |
)
|
141 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
cache_examples=False,
|
143 |
-
stop_btn="Stop
|
144 |
fill_height=True,
|
145 |
multimodal=True,
|
|
|
146 |
)
|
147 |
|
148 |
if __name__ == "__main__":
|
|
|
3 |
from typing import Dict, List
|
4 |
|
5 |
import gradio as gr
|
6 |
+
|
7 |
+
# import spaces
|
8 |
import torch
|
9 |
from PIL import Image
|
10 |
from transformers import (
|
|
|
71 |
return messages, images
|
72 |
|
73 |
|
74 |
+
# @spaces.GPU
|
75 |
+
def bot_streaming(message: Dict, history: List, max_new_tokens: int = 250):
|
76 |
"""
|
77 |
Generate streaming responses for the chatbot.
|
78 |
|
|
|
130 |
|
131 |
demo = gr.ChatInterface(
|
132 |
fn=bot_streaming,
|
133 |
+
textbox=gr.MultimodalTextbox(placeholder="Ask me anything..."),
|
134 |
additional_inputs=[
|
135 |
gr.Slider(
|
136 |
minimum=10,
|
|
|
140 |
label="Maximum number of new tokens to generate",
|
141 |
)
|
142 |
],
|
143 |
+
examples=[
|
144 |
+
[
|
145 |
+
{
|
146 |
+
"text": "What is the total amount in this bill?",
|
147 |
+
"files": ["./examples/01.jpg"],
|
148 |
+
},
|
149 |
+
200,
|
150 |
+
],
|
151 |
+
[
|
152 |
+
{
|
153 |
+
"text": "What is the name of the restaurant in this bill?",
|
154 |
+
"files": ["./examples/02.jpg"],
|
155 |
+
},
|
156 |
+
200,
|
157 |
+
],
|
158 |
+
],
|
159 |
cache_examples=False,
|
160 |
+
stop_btn="Stop",
|
161 |
fill_height=True,
|
162 |
multimodal=True,
|
163 |
+
type="messages",
|
164 |
)
|
165 |
|
166 |
if __name__ == "__main__":
|