Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -72,6 +72,19 @@ def identify_and_save_blob(blob_path):
|
|
72 |
except Exception as e:
|
73 |
raise ValueError(f"An error occurred while processing the file: {e}")
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
@spaces.GPU()
|
76 |
def generate(
|
77 |
message: str,
|
@@ -170,60 +183,72 @@ def generate(
|
|
170 |
outputs.append(text)
|
171 |
yield "".join(outputs)
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
-
|
229 |
-
demo.queue(max_size=20).launch()
|
|
|
72 |
except Exception as e:
|
73 |
raise ValueError(f"An error occurred while processing the file: {e}")
|
74 |
|
75 |
+
def process_vision_info(messages):
|
76 |
+
"""Processes vision information (images or videos) from messages."""
|
77 |
+
image_inputs = []
|
78 |
+
video_inputs = []
|
79 |
+
for message in messages:
|
80 |
+
for content in message["content"]:
|
81 |
+
if content["type"] == "image":
|
82 |
+
image = Image.open(content["image"])
|
83 |
+
image_inputs.append(image)
|
84 |
+
elif content["type"] == "video":
|
85 |
+
video_inputs.append(content["video"])
|
86 |
+
return image_inputs, video_inputs
|
87 |
+
|
88 |
@spaces.GPU()
|
89 |
def generate(
|
90 |
message: str,
|
|
|
183 |
outputs.append(text)
|
184 |
yield "".join(outputs)
|
185 |
|
186 |
+
css = """
|
187 |
+
#output {
|
188 |
+
height: 500px;
|
189 |
+
overflow: auto;
|
190 |
+
border: 1px solid #ccc;
|
191 |
+
}
|
192 |
+
"""
|
193 |
+
|
194 |
+
with gr.Blocks(css=css) as demo:
|
195 |
+
gr.Markdown(DESCRIPTION)
|
196 |
+
|
197 |
+
with gr.Tab(label="Chat Interface"):
|
198 |
+
chat_interface = gr.ChatInterface(
|
199 |
+
fn=generate,
|
200 |
+
additional_inputs=[
|
201 |
+
gr.Slider(
|
202 |
+
label="Max new tokens",
|
203 |
+
minimum=1,
|
204 |
+
maximum=MAX_MAX_NEW_TOKENS,
|
205 |
+
step=1,
|
206 |
+
value=DEFAULT_MAX_NEW_TOKENS,
|
207 |
+
),
|
208 |
+
gr.Slider(
|
209 |
+
label="Temperature",
|
210 |
+
minimum=0.1,
|
211 |
+
maximum=4.0,
|
212 |
+
step=0.1,
|
213 |
+
value=0.6,
|
214 |
+
),
|
215 |
+
gr.Slider(
|
216 |
+
label="Top-p (nucleus sampling)",
|
217 |
+
minimum=0.05,
|
218 |
+
maximum=1.0,
|
219 |
+
step=0.05,
|
220 |
+
value=0.9,
|
221 |
+
),
|
222 |
+
gr.Slider(
|
223 |
+
label="Top-k",
|
224 |
+
minimum=1,
|
225 |
+
maximum=1000,
|
226 |
+
step=1,
|
227 |
+
value=50,
|
228 |
+
),
|
229 |
+
gr.Slider(
|
230 |
+
label="Repetition penalty",
|
231 |
+
minimum=1.0,
|
232 |
+
maximum=2.0,
|
233 |
+
step=0.05,
|
234 |
+
value=1.2,
|
235 |
+
),
|
236 |
+
],
|
237 |
+
stop_btn=None,
|
238 |
+
examples=[
|
239 |
+
["Hello there! How are you doing?"],
|
240 |
+
["Can you explain briefly to me what is the Python programming language?"],
|
241 |
+
["Explain the plot of Cinderella in a sentence."],
|
242 |
+
["How many hours does it take a man to eat a Helicopter?"],
|
243 |
+
["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
|
244 |
+
],
|
245 |
+
cache_examples=False,
|
246 |
+
type="messages",
|
247 |
+
description=DESCRIPTION,
|
248 |
+
css_paths="style.css",
|
249 |
+
fill_height=True,
|
250 |
+
textbox=gr.MultimodalTextbox(),
|
251 |
+
multimodal=True,
|
252 |
+
)
|
253 |
|
254 |
+
demo.launch(debug=True)
|
|