Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ 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, max_new_tokens=250,
|
35 |
if client is None:
|
36 |
initialize_client(api_key)
|
37 |
|
@@ -73,36 +73,41 @@ def bot_streaming(message, history, max_new_tokens=250, api_key=None, max_histor
|
|
73 |
time.sleep(0.01)
|
74 |
yield buffer
|
75 |
|
76 |
-
except
|
77 |
if "Request Entity Too Large" in str(e):
|
78 |
yield "The image is too large. Please try with a smaller image or compress the existing one."
|
79 |
else:
|
80 |
yield f"An error occurred: {str(e)}"
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
if __name__ == "__main__":
|
108 |
demo.launch(debug=True)
|
|
|
31 |
img.save(buffered, format="JPEG", quality=quality)
|
32 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
33 |
|
34 |
+
def bot_streaming(message, history, api_key, max_new_tokens=250, max_history=5):
|
35 |
if client is None:
|
36 |
initialize_client(api_key)
|
37 |
|
|
|
73 |
time.sleep(0.01)
|
74 |
yield buffer
|
75 |
|
76 |
+
except Exception as e:
|
77 |
if "Request Entity Too Large" in str(e):
|
78 |
yield "The image is too large. Please try with a smaller image or compress the existing one."
|
79 |
else:
|
80 |
yield f"An error occurred: {str(e)}"
|
81 |
|
82 |
+
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 and get started!")
|
85 |
+
|
86 |
+
api_key = gr.Textbox(
|
87 |
+
label="Together API Key",
|
88 |
+
placeholder="Enter your API key here.",
|
89 |
+
type="password"
|
90 |
+
)
|
91 |
+
|
92 |
+
chatbot = gr.ChatInterface(
|
93 |
+
fn=bot_streaming,
|
94 |
+
textbox=gr.MultimodalTextbox(),
|
95 |
+
additional_inputs=[
|
96 |
+
gr.Slider(
|
97 |
+
minimum=10,
|
98 |
+
maximum=500,
|
99 |
+
value=250,
|
100 |
+
step=10,
|
101 |
+
label="Maximum number of new tokens to generate",
|
102 |
+
)
|
103 |
+
],
|
104 |
+
cache_examples=False,
|
105 |
+
stop_btn="Stop Generation",
|
106 |
+
fill_height=True,
|
107 |
+
multimodal=True
|
108 |
+
)
|
109 |
+
|
110 |
+
api_key.change(lambda x: x, inputs=[api_key], outputs=[chatbot.additional_inputs[0]])
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
demo.launch(debug=True)
|