ZahirJS commited on
Commit
8f82404
·
verified ·
1 Parent(s): a0c7e7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -4,7 +4,7 @@ from PIL import Image
4
  import io
5
  import base64
6
 
7
- def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M") -> dict:
8
  """
9
  Generate QR code from text/URL
10
 
@@ -14,7 +14,7 @@ def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M
14
  error_correction (str): Error correction level (L, M, Q, H)
15
 
16
  Returns:
17
- dict: QR code information with qr_url field containing displayable image
18
  """
19
 
20
  if not text.strip():
@@ -51,12 +51,11 @@ def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M
51
  img_base64 = base64.b64encode(buffer.getvalue()).decode()
52
 
53
  return {
54
- "qr_code_image": f"data:image/png;base64,{img_base64}",
55
- "info": f"QR code generated for: {text}"
56
  }
57
 
58
  except Exception as e:
59
- return {"error": f"Failed to generate QR code: {str(e)}"}
60
 
61
  if __name__ == "__main__":
62
  demo = gr.Interface(
@@ -66,7 +65,7 @@ if __name__ == "__main__":
66
  gr.Dropdown(["small", "medium", "large"], value="medium", label="Size"),
67
  gr.Dropdown(["L", "M", "Q", "H"], value="M", label="Error Correction")
68
  ],
69
- outputs=gr.JSON(),
70
  title="QR Code Generator for Claude",
71
  description="Generate QR codes for Claude MCP integration"
72
  )
 
4
  import io
5
  import base64
6
 
7
+ def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M") -> str:
8
  """
9
  Generate QR code from text/URL
10
 
 
14
  error_correction (str): Error correction level (L, M, Q, H)
15
 
16
  Returns:
17
+ str: Base64 data URL that can be displayed as QR code image
18
  """
19
 
20
  if not text.strip():
 
51
  img_base64 = base64.b64encode(buffer.getvalue()).decode()
52
 
53
  return {
54
+ f"data:image/png;base64,{img_base64}"
 
55
  }
56
 
57
  except Exception as e:
58
+ return f"Error: Failed to generate QR code: {str(e)}"
59
 
60
  if __name__ == "__main__":
61
  demo = gr.Interface(
 
65
  gr.Dropdown(["small", "medium", "large"], value="medium", label="Size"),
66
  gr.Dropdown(["L", "M", "Q", "H"], value="M", label="Error Correction")
67
  ],
68
+ outputs=gr.Textbox(label="QR Code Data URL"),
69
  title="QR Code Generator for Claude",
70
  description="Generate QR codes for Claude MCP integration"
71
  )