Spaces:
Runtime error
Runtime error
hassanelmghari
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -14,11 +14,11 @@ client = None
|
|
14 |
def initialize_client(api_key=None):
|
15 |
global client
|
16 |
if api_key:
|
17 |
-
|
18 |
-
|
19 |
client = Together()
|
20 |
else:
|
21 |
-
raise ValueError("Please provide
|
22 |
|
23 |
def encode_image(image_path, max_size=(800, 800), quality=85):
|
24 |
with Image.open(image_path) as img:
|
@@ -31,9 +31,9 @@ def encode_image(image_path, max_size=(800, 800), quality=85):
|
|
31 |
img.save(buffered, format="JPEG", quality=quality)
|
32 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
33 |
|
34 |
-
def bot_streaming(message, history,
|
35 |
if client is None:
|
36 |
-
initialize_client(
|
37 |
|
38 |
txt = message["text"]
|
39 |
messages = []
|
@@ -83,9 +83,9 @@ with gr.Blocks() as demo:
|
|
83 |
gr.Markdown("# Meta Llama-3.2-11B-Vision-Instruct (FREE)")
|
84 |
gr.Markdown("Try the new Llama 3.2 11B Vision API by Meta for free through Together AI. Upload an image, and start chatting about it. Just paste in your [Together AI API key](https://api.together.xyz/settings/api-keys) and get started!")
|
85 |
|
86 |
-
|
87 |
label="Together API Key",
|
88 |
-
placeholder="Enter your
|
89 |
type="password"
|
90 |
)
|
91 |
|
@@ -107,7 +107,7 @@ with gr.Blocks() as demo:
|
|
107 |
multimodal=True
|
108 |
)
|
109 |
|
110 |
-
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
demo.launch(debug=True)
|
|
|
14 |
def initialize_client(api_key=None):
|
15 |
global client
|
16 |
if api_key:
|
17 |
+
os.environ["TOGETHER_API_KEY"] = api_key
|
18 |
+
if "TOGETHER_API_KEY" in os.environ:
|
19 |
client = Together()
|
20 |
else:
|
21 |
+
raise ValueError("Please provide a Together API Key")
|
22 |
|
23 |
def encode_image(image_path, max_size=(800, 800), quality=85):
|
24 |
with Image.open(image_path) as img:
|
|
|
31 |
img.save(buffered, format="JPEG", quality=quality)
|
32 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
33 |
|
34 |
+
def bot_streaming(message, history, together_api_key, max_new_tokens=250, max_history=5):
|
35 |
if client is None:
|
36 |
+
initialize_client(together_api_key)
|
37 |
|
38 |
txt = message["text"]
|
39 |
messages = []
|
|
|
83 |
gr.Markdown("# Meta Llama-3.2-11B-Vision-Instruct (FREE)")
|
84 |
gr.Markdown("Try the new Llama 3.2 11B Vision API by Meta for free through Together AI. Upload an image, and start chatting about it. Just paste in your [Together AI API key](https://api.together.xyz/settings/api-keys) and get started!")
|
85 |
|
86 |
+
together_api_key = gr.Textbox(
|
87 |
label="Together API Key",
|
88 |
+
placeholder="Enter your TOGETHER_API_KEY here",
|
89 |
type="password"
|
90 |
)
|
91 |
|
|
|
107 |
multimodal=True
|
108 |
)
|
109 |
|
110 |
+
together_api_key.change(lambda x: x, inputs=[together_api_key], outputs=[chatbot.additional_inputs[0]])
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
demo.launch(debug=True)
|