akhaliq HF staff commited on
Commit
e98c6cb
1 Parent(s): d107cdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- import os
3
  from together import Together
4
  import base64
5
  from io import BytesIO
@@ -7,15 +6,14 @@ from PIL import Image
7
  import numpy as np
8
  import traceback
9
 
10
- # Initialize the Together client
11
- api_key = os.environ.get('TOGETHER_API_KEY')
12
- client = Together(api_key=api_key)
13
-
14
- def generate_gradio_app(image):
15
  if not api_key:
16
- return "Error: TOGETHER_API_KEY not set. Please check your API key."
17
 
18
  try:
 
 
 
19
  # Convert numpy array to PIL Image
20
  if isinstance(image, np.ndarray):
21
  image = Image.fromarray(image.astype('uint8'), 'RGB')
@@ -82,11 +80,13 @@ Please generate the entire Gradio code based on the provided image."""
82
  except Exception as e:
83
  error_message = str(e)
84
  stack_trace = traceback.format_exc()
85
- return f"An error occurred: {error_message}\n\nStack trace:\n{stack_trace}\n\nPlease try again or check your API key and connection."
86
 
87
  with gr.Blocks() as demo:
88
  gr.Markdown("# Generate Gradio App from Wireframe")
89
- gr.Markdown("Upload an image of your UI design, and we'll generate Gradio code to recreate it.")
 
 
90
 
91
  with gr.Row():
92
  with gr.Column(scale=1):
@@ -98,7 +98,7 @@ with gr.Blocks() as demo:
98
 
99
  generate_button.click(
100
  fn=generate_gradio_app,
101
- inputs=[image_input],
102
  outputs=[code_output]
103
  )
104
 
 
1
  import gradio as gr
 
2
  from together import Together
3
  import base64
4
  from io import BytesIO
 
6
  import numpy as np
7
  import traceback
8
 
9
+ def generate_gradio_app(api_key, image):
 
 
 
 
10
  if not api_key:
11
+ return "Error: API key not provided. Please enter your Together API key."
12
 
13
  try:
14
+ # Initialize the Together client with the provided API key
15
+ client = Together(api_key=api_key)
16
+
17
  # Convert numpy array to PIL Image
18
  if isinstance(image, np.ndarray):
19
  image = Image.fromarray(image.astype('uint8'), 'RGB')
 
80
  except Exception as e:
81
  error_message = str(e)
82
  stack_trace = traceback.format_exc()
83
+ return f"An error occurred: {error_message}\n\nStack trace:\n{stack_trace}\n\nPlease check your API key and try again."
84
 
85
  with gr.Blocks() as demo:
86
  gr.Markdown("# Generate Gradio App from Wireframe")
87
+ gr.Markdown("Enter your Together API key, upload an image of your UI design, and we'll generate Gradio code to recreate it.")
88
+
89
+ api_key_input = gr.Textbox(label="Enter your Together API Key", type="password")
90
 
91
  with gr.Row():
92
  with gr.Column(scale=1):
 
98
 
99
  generate_button.click(
100
  fn=generate_gradio_app,
101
+ inputs=[api_key_input, image_input],
102
  outputs=[code_output]
103
  )
104