Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,17 +8,25 @@ from threading import Thread
|
|
8 |
import time
|
9 |
|
10 |
# Initialize Together client
|
11 |
-
client =
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def encode_image(image_path):
|
18 |
with open(image_path, "rb") as image_file:
|
19 |
return base64.b64encode(image_file.read()).decode('utf-8')
|
20 |
|
21 |
-
def bot_streaming(message, history, max_new_tokens=250):
|
|
|
|
|
|
|
22 |
txt = message["text"]
|
23 |
messages = []
|
24 |
images = []
|
@@ -43,7 +51,7 @@ def bot_streaming(message, history, max_new_tokens=250):
|
|
43 |
messages.append({"role": "user", "content": [{"type": "text", "text": txt}]})
|
44 |
|
45 |
stream = client.chat.completions.create(
|
46 |
-
model="meta-llama/Llama-Vision-
|
47 |
messages=messages,
|
48 |
max_tokens=max_new_tokens,
|
49 |
stream=True,
|
@@ -58,7 +66,7 @@ def bot_streaming(message, history, max_new_tokens=250):
|
|
58 |
|
59 |
demo = gr.ChatInterface(
|
60 |
fn=bot_streaming,
|
61 |
-
title="Meta Llama
|
62 |
textbox=gr.MultimodalTextbox(),
|
63 |
additional_inputs=[
|
64 |
gr.Slider(
|
@@ -67,10 +75,14 @@ demo = gr.ChatInterface(
|
|
67 |
value=250,
|
68 |
step=10,
|
69 |
label="Maximum number of new tokens to generate",
|
|
|
|
|
|
|
|
|
70 |
)
|
71 |
],
|
72 |
cache_examples=False,
|
73 |
-
description="Try Multimodal Llama by Meta with the Together API in this demo. Upload an image, and start chatting about it",
|
74 |
stop_btn="Stop Generation",
|
75 |
fill_height=True,
|
76 |
multimodal=True
|
|
|
8 |
import time
|
9 |
|
10 |
# Initialize Together client
|
11 |
+
client = None
|
12 |
|
13 |
+
def initialize_client(api_key=None):
|
14 |
+
global client
|
15 |
+
if api_key:
|
16 |
+
client = Together(api_key=api_key)
|
17 |
+
elif "TOGETHER_API_KEY" in os.environ:
|
18 |
+
client = Together()
|
19 |
+
else:
|
20 |
+
raise ValueError("Please provide an API key or set the TOGETHER_API_KEY environment variable")
|
21 |
|
22 |
def encode_image(image_path):
|
23 |
with open(image_path, "rb") as image_file:
|
24 |
return base64.b64encode(image_file.read()).decode('utf-8')
|
25 |
|
26 |
+
def bot_streaming(message, history, max_new_tokens=250, api_key=None):
|
27 |
+
if client is None:
|
28 |
+
initialize_client(api_key)
|
29 |
+
|
30 |
txt = message["text"]
|
31 |
messages = []
|
32 |
images = []
|
|
|
51 |
messages.append({"role": "user", "content": [{"type": "text", "text": txt}]})
|
52 |
|
53 |
stream = client.chat.completions.create(
|
54 |
+
model="meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
|
55 |
messages=messages,
|
56 |
max_tokens=max_new_tokens,
|
57 |
stream=True,
|
|
|
66 |
|
67 |
demo = gr.ChatInterface(
|
68 |
fn=bot_streaming,
|
69 |
+
title="Meta Llama-3.2-90B-Vision-Instruct-Turbo",
|
70 |
textbox=gr.MultimodalTextbox(),
|
71 |
additional_inputs=[
|
72 |
gr.Slider(
|
|
|
75 |
value=250,
|
76 |
step=10,
|
77 |
label="Maximum number of new tokens to generate",
|
78 |
+
),
|
79 |
+
gr.Textbox(
|
80 |
+
label="Together API Key (optional)",
|
81 |
+
placeholder="Enter your API key here. (optional)",
|
82 |
)
|
83 |
],
|
84 |
cache_examples=False,
|
85 |
+
description="Try Multimodal Llama by Meta with the Together API in this demo. Upload an image, and start chatting about it. You can provide your own API key or use the default one.",
|
86 |
stop_btn="Stop Generation",
|
87 |
fill_height=True,
|
88 |
multimodal=True
|