Spaces:
Running
Running
rename main
Browse files- README.md +1 -1
- env_utils.py +18 -0
- requirements.txt +1 -1
- app.py → svg_editor_gradio.py +8 -6
README.md
CHANGED
@@ -5,7 +5,7 @@ colorFrom: indigo
|
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.39.0
|
8 |
-
app_file:
|
9 |
pinned: false
|
10 |
---
|
11 |
|
|
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.39.0
|
8 |
+
app_file: svg_editor_gradio.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
env_utils.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv, find_dotenv
|
2 |
+
import os
|
3 |
+
|
4 |
+
def getenvvar(varname):
|
5 |
+
# needed to strip env var of any remaining quotes - might be added by deployment scripts
|
6 |
+
val = os.environ.get(varname)
|
7 |
+
if val is None:
|
8 |
+
f"Environment variable {varname} not found"
|
9 |
+
else:
|
10 |
+
return val.strip('"').strip("'")
|
11 |
+
|
12 |
+
def load_credentials():
|
13 |
+
load_dotenv(find_dotenv()) # take environment variables from .env.
|
14 |
+
apikey = getenvvar("WXAI_APIKEY")
|
15 |
+
apiendpoint = getenvvar("WXAI_ENDPOINT")
|
16 |
+
projectid = getenvvar("WXAI_PROJECT")
|
17 |
+
status = apiendpoint is not None and apikey is not None and projectid is not None
|
18 |
+
return status, apiendpoint, apikey, projectid
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
gradio
|
2 |
-
ibm_watsonx_ai
|
|
|
1 |
gradio
|
2 |
+
ibm_watsonx_ai==1.1.2
|
app.py → svg_editor_gradio.py
RENAMED
@@ -1,5 +1,5 @@
|
|
1 |
# Remi Serra 202407
|
2 |
-
|
3 |
import gradio as gr
|
4 |
from random import randrange
|
5 |
from svg_utils import decode_b64_string_to_pretty_xml, encode_svg_xml_to_b64_string
|
@@ -187,6 +187,8 @@ with gr.Blocks() as demo:
|
|
187 |
- Describe an SVG: Upload, paste or generate an SVG file, Select the prompt template 'Describe SVG' and click 'Submit' """
|
188 |
)
|
189 |
|
|
|
|
|
190 |
# init state - note gr.State() initial value must be deep-copyable - my wx_engine class is not
|
191 |
wx_engine_state = gr.State(None)
|
192 |
with gr.Column():
|
@@ -230,13 +232,13 @@ with gr.Blocks() as demo:
|
|
230 |
# credentials
|
231 |
with gr.Accordion("Credentials:", open=True):
|
232 |
wx_creds_endpoint = gr.Textbox(
|
233 |
-
label="Endpoint",
|
234 |
-
|
235 |
-
|
|
|
236 |
)
|
237 |
-
wx_creds_apikey = gr.Textbox(label="API key", max_lines=1)
|
238 |
wx_creds_projectid = gr.Textbox(
|
239 |
-
label="Project id", max_lines=1
|
240 |
)
|
241 |
wx_connect_btn = gr.Button("Connect")
|
242 |
# model
|
|
|
1 |
# Remi Serra 202407
|
2 |
+
from env_utils import load_credentials
|
3 |
import gradio as gr
|
4 |
from random import randrange
|
5 |
from svg_utils import decode_b64_string_to_pretty_xml, encode_svg_xml_to_b64_string
|
|
|
187 |
- Describe an SVG: Upload, paste or generate an SVG file, Select the prompt template 'Describe SVG' and click 'Submit' """
|
188 |
)
|
189 |
|
190 |
+
# load env variables
|
191 |
+
status, env_apiendpoint, env_apikey, env_projectid = load_credentials()
|
192 |
# init state - note gr.State() initial value must be deep-copyable - my wx_engine class is not
|
193 |
wx_engine_state = gr.State(None)
|
194 |
with gr.Column():
|
|
|
232 |
# credentials
|
233 |
with gr.Accordion("Credentials:", open=True):
|
234 |
wx_creds_endpoint = gr.Textbox(
|
235 |
+
label="Endpoint", value=env_apiendpoint, max_lines=1
|
236 |
+
)
|
237 |
+
wx_creds_apikey = gr.Textbox(
|
238 |
+
label="API key", value=env_apikey, max_lines=1
|
239 |
)
|
|
|
240 |
wx_creds_projectid = gr.Textbox(
|
241 |
+
label="Project id", value=env_projectid, max_lines=1
|
242 |
)
|
243 |
wx_connect_btn = gr.Button("Connect")
|
244 |
# model
|