kz919 commited on
Commit
e277252
·
verified ·
1 Parent(s): c4dec28

update the app to use default API_KEY if it's not provided

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -6,10 +6,9 @@ from PIL import Image
6
  import numpy as np
7
  import os
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 write something first."
15
 
@@ -23,6 +22,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,8 +65,11 @@ def sketch_to_text(image):
61
  # Create the Gradio interface
62
  with gr.Blocks() as iface:
63
  gr.Markdown("# Pix2Latex")
64
- gr.Markdown("Transcribing handwritten forumla into latex with Llama3.2 instruct")
65
-
 
 
 
66
  with gr.Column(scale=1):
67
  input_image = gr.ImageEditor()
68
 
@@ -72,7 +79,7 @@ with gr.Blocks() as iface:
72
  with gr.Column(scale=1):
73
  output2 = gr.Markdown(label="Rendered")
74
 
75
- input_image.change(fn=sketch_to_text, inputs=input_image, outputs=[output1, output2])
76
 
77
  gr.Markdown("How to use: 1. write your formula in the box above. 2. See it in real time, have fun doing math?")
78
 
 
6
  import numpy as np
7
  import os
8
 
 
9
  URL = os.environ['URL']
10
 
11
+ def sketch_to_text(image, api_key):
12
  if image is None or not isinstance(image, dict) or 'composite' not in image:
13
  return "Please write something first."
14
 
 
22
  pil_image.save(buffered, format="PNG")
23
  img_str = base64.b64encode(buffered.getvalue()).decode()
24
 
25
+ if api_key:
26
+ API_KEY = api_key
27
+ else:
28
+ API_KEY = os.environ['API_KEY']
29
+
30
  # Prepare the API request
31
  headers = {
32
  "Content-Type": "application/json",
 
65
  # Create the Gradio interface
66
  with gr.Blocks() as iface:
67
  gr.Markdown("# Pix2Latex")
68
+ gr.Markdown("Transcribing handwritten forumla into latex with Llama3.2 instruct. [Powered by SambaNova Cloud, Get Your API Key Here](https://cloud.sambanova.ai/apis)")
69
+
70
+ with gr.Row():
71
+ api_key = gr.Textbox(label="API Key", type="password", placeholder="(Optional) Enter your API key here for more availability. ")
72
+
73
  with gr.Column(scale=1):
74
  input_image = gr.ImageEditor()
75
 
 
79
  with gr.Column(scale=1):
80
  output2 = gr.Markdown(label="Rendered")
81
 
82
+ input_image.change(fn=sketch_to_text, inputs=[input_image, api_key], outputs=[output1, output2])
83
 
84
  gr.Markdown("How to use: 1. write your formula in the box above. 2. See it in real time, have fun doing math?")
85