Simonlob commited on
Commit
4abfaf2
·
verified ·
1 Parent(s): 741dac8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -93
app.py CHANGED
@@ -50,8 +50,8 @@ def generate_qr(url, fill_color=None, back_color=None):
50
  raise ValueError("URL or data cannot be empty")
51
 
52
  # Convert empty strings to None
53
- fill_color = fill_color.strip() if fill_color else None
54
- back_color = back_color.strip() if back_color else None
55
 
56
  # Generate QR code with optional color parameters
57
  return get_qr_image(url, fill_color, back_color)
@@ -71,98 +71,9 @@ iface = gr.Interface(
71
  ],
72
  outputs=gr.Image(label="QR Code"),
73
  title="QR Code Generator",
74
- description="Generate a QR code from a URL or text with optional color customization.",
75
- examples=[
76
- ["https://example.com"],
77
- ["Hello World", "blue", "white"]
78
- ]
79
  )
80
 
81
  # Launch the app
82
  if __name__ == "__main__":
83
- iface.launch()
84
-
85
-
86
-
87
-
88
-
89
-
90
- # import gradio as gr
91
- # import qrcode
92
- # import qrcode.constants
93
- # from PIL import Image
94
-
95
- # def get_qr_image(data: str, fill_color: str = None, back_color: str = None):
96
- # """
97
- # Generate a QR code image from the given data and optional color parameters.
98
-
99
- # Args:
100
- # data (str): The data to encode in the QR code
101
- # fill_color (str, optional): Color of the QR code modules (default: black)
102
- # back_color (str, optional): Background color of the QR code (default: white)
103
-
104
- # Returns:
105
- # PIL.Image: Generated QR code image
106
- # """
107
- # qr = qrcode.QRCode(
108
- # version=1,
109
- # error_correction=qrcode.constants.ERROR_CORRECT_H,
110
- # box_size=10,
111
- # border=4,
112
- # )
113
-
114
- # qr.add_data(data)
115
- # qr.make(fit=True)
116
-
117
- # # Explicitly create a PIL Image and convert to RGB mode
118
- # img = qr.make_image(fill_color=fill_color, back_color=back_color)
119
- # img = img.convert('RGB')
120
-
121
- # return img
122
-
123
- # def generate_qr(url, fill_color=None, back_color=None):
124
- # """
125
- # Wrapper function for Gradio interface to generate QR code.
126
- # Handles potential errors and provides default behavior.
127
-
128
- # Args:
129
- # url (str): URL or data to encode
130
- # fill_color (str, optional): Color of QR code modules
131
- # back_color (str, optional): Background color of QR code
132
-
133
- # Returns:
134
- # PIL.Image: Generated QR code image
135
- # """
136
- # try:
137
- # # Validate URL/data is not empty
138
- # if not url:
139
- # raise ValueError("URL or data cannot be empty")
140
-
141
- # # Convert empty strings to None
142
- # fill_color = fill_color.strip() if fill_color else 'black'
143
- # back_color = back_color.strip() if back_color else 'white'
144
-
145
- # # Generate QR code with optional color parameters
146
- # return get_qr_image(url, fill_color, back_color)
147
-
148
- # except Exception as e:
149
- # # Error handling for Gradio
150
- # gr.Warning(f"Error generating QR code: {str(e)}")
151
- # return None
152
-
153
- # # Create Gradio interface
154
- # iface = gr.Interface(
155
- # fn=generate_qr,
156
- # inputs=[
157
- # gr.Textbox(label="URL or Data"),
158
- # gr.Textbox(label="Fill Color (optional)", placeholder="e.g., 'blue', '#FF0000'"),
159
- # gr.Textbox(label="Background Color (optional)", placeholder="e.g., 'white', '#FFFFFF'")
160
- # ],
161
- # outputs=gr.Image(label="QR Code"),
162
- # title="QR Code Generator",
163
- # description="Generate a QR code from a URL or text with optional color customization."
164
- # )
165
-
166
- # # Launch the app
167
- # if __name__ == "__main__":
168
- # iface.launch()
 
50
  raise ValueError("URL or data cannot be empty")
51
 
52
  # Convert empty strings to None
53
+ fill_color = fill_color.strip() if fill_color else 'black'
54
+ back_color = back_color.strip() if back_color else 'white'
55
 
56
  # Generate QR code with optional color parameters
57
  return get_qr_image(url, fill_color, back_color)
 
71
  ],
72
  outputs=gr.Image(label="QR Code"),
73
  title="QR Code Generator",
74
+ description="Generate a QR code from a URL or text with optional color customization."
 
 
 
 
75
  )
76
 
77
  # Launch the app
78
  if __name__ == "__main__":
79
+ iface.launch()