Spaces:
Running
Running
update app to allow default API key
Browse files
app.py
CHANGED
@@ -5,11 +5,9 @@ import requests
|
|
5 |
import io
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
8 |
-
|
9 |
-
API_KEY = os.environ['API_KEY']
|
10 |
URL = os.environ['URL']
|
11 |
|
12 |
-
def sketch_to_text(image):
|
13 |
if image is None or not isinstance(image, dict) or 'composite' not in image:
|
14 |
return "Please draw something first."
|
15 |
|
@@ -23,6 +21,11 @@ def sketch_to_text(image):
|
|
23 |
pil_image.save(buffered, format="PNG")
|
24 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
25 |
|
|
|
|
|
|
|
|
|
|
|
26 |
# Prepare the API request
|
27 |
headers = {
|
28 |
"Content-Type": "application/json",
|
@@ -61,15 +64,16 @@ def sketch_to_text(image):
|
|
61 |
# Create the Gradio interface
|
62 |
with gr.Blocks() as iface:
|
63 |
gr.Markdown("# Pictionary with Llama3.2 Instruct")
|
64 |
-
gr.Markdown("Draw something and let
|
65 |
-
|
|
|
66 |
with gr.Column(scale=1):
|
67 |
output = gr.Textbox(label="Description", lines=5)
|
68 |
|
69 |
with gr.Column(scale=1):
|
70 |
input_image = gr.ImageEditor()
|
71 |
|
72 |
-
input_image.change(fn=sketch_to_text, inputs=input_image, outputs=output)
|
73 |
|
74 |
gr.Markdown("How to use: 1. Draw your sketch in the box above. 2. See guessing in real time. Have fun sketching!")
|
75 |
|
|
|
5 |
import io
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
|
|
|
|
8 |
URL = os.environ['URL']
|
9 |
|
10 |
+
def sketch_to_text(image, api_key):
|
11 |
if image is None or not isinstance(image, dict) or 'composite' not in image:
|
12 |
return "Please draw something first."
|
13 |
|
|
|
21 |
pil_image.save(buffered, format="PNG")
|
22 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
23 |
|
24 |
+
if api_key:
|
25 |
+
API_KEY = api_key
|
26 |
+
else:
|
27 |
+
API_KEY = os.environ['API_KEY']
|
28 |
+
|
29 |
# Prepare the API request
|
30 |
headers = {
|
31 |
"Content-Type": "application/json",
|
|
|
64 |
# Create the Gradio interface
|
65 |
with gr.Blocks() as iface:
|
66 |
gr.Markdown("# Pictionary with Llama3.2 Instruct")
|
67 |
+
gr.Markdown("Draw something and let Llama3.2 guess it! [Powered by SambaNova Cloud, Get Your API Key Here](https://cloud.sambanova.ai/apis)")
|
68 |
+
with gr.Row():
|
69 |
+
api_key = gr.Textbox(label="API Key", type="password", placeholder="(Optional) Enter your API key here for more availability")
|
70 |
with gr.Column(scale=1):
|
71 |
output = gr.Textbox(label="Description", lines=5)
|
72 |
|
73 |
with gr.Column(scale=1):
|
74 |
input_image = gr.ImageEditor()
|
75 |
|
76 |
+
input_image.change(fn=sketch_to_text, inputs=[input_image, api_key], outputs=output)
|
77 |
|
78 |
gr.Markdown("How to use: 1. Draw your sketch in the box above. 2. See guessing in real time. Have fun sketching!")
|
79 |
|