Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- gradio_app.py +4 -4
gradio_app.py
CHANGED
@@ -11,7 +11,8 @@ DESCRIPTION = "Welcome to the AIN Arabic VLM chatbot. The best Arabic-English VL
|
|
11 |
TOP_N_HISTORY = 2
|
12 |
LOGO_PATH = "https://huggingface.co/spaces/ahmedheakl/AIN-Arabic-VLM/resolve/main/logo.jpeg"
|
13 |
|
14 |
-
|
|
|
15 |
|
16 |
def load_chat(
|
17 |
base_url: str,
|
@@ -39,7 +40,7 @@ def load_chat(
|
|
39 |
for i, h in enumerate(history):
|
40 |
content = h.get("content", "")
|
41 |
if isinstance(content, tuple):
|
42 |
-
hist.append({"role": "user", "content": [{"type": "image_url", "image_url": {"url": content[0]}}]})
|
43 |
else:
|
44 |
hist.append({"role": "user", "content": [{"type": "text", "text": content}]})
|
45 |
history = hist
|
@@ -49,8 +50,7 @@ def load_chat(
|
|
49 |
]
|
50 |
if files:
|
51 |
src_path = files[0]
|
52 |
-
image_url
|
53 |
-
content.append({"type": "image_url", "image_url": {"url": image_url}})
|
54 |
stream = client.chat.completions.create(
|
55 |
model=model,
|
56 |
messages=history + [{"role": "user", "content": content}],
|
|
|
11 |
TOP_N_HISTORY = 2
|
12 |
LOGO_PATH = "https://huggingface.co/spaces/ahmedheakl/AIN-Arabic-VLM/resolve/main/logo.jpeg"
|
13 |
|
14 |
+
def get_gradio_url(path: str) -> str:
|
15 |
+
return f"https://{USERNAME}-{SPACE_NAME}.hf.space/gradio_api/file={path}"
|
16 |
|
17 |
def load_chat(
|
18 |
base_url: str,
|
|
|
40 |
for i, h in enumerate(history):
|
41 |
content = h.get("content", "")
|
42 |
if isinstance(content, tuple):
|
43 |
+
hist.append({"role": "user", "content": [{"type": "image_url", "image_url": {"url": get_gradio_url(content[0])}}]})
|
44 |
else:
|
45 |
hist.append({"role": "user", "content": [{"type": "text", "text": content}]})
|
46 |
history = hist
|
|
|
50 |
]
|
51 |
if files:
|
52 |
src_path = files[0]
|
53 |
+
content.append({"type": "image_url", "image_url": {"url": get_gradio_url(src_path)}})
|
|
|
54 |
stream = client.chat.completions.create(
|
55 |
model=model,
|
56 |
messages=history + [{"role": "user", "content": content}],
|