Spaces:
Sleeping
Sleeping
Ifeanyi
commited on
Commit
·
442a93e
1
Parent(s):
1246acc
MCP server files
Browse files- requirements.txt +4 -0
- server.py +41 -0
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==6.0.2
|
| 2 |
+
numpy
|
| 3 |
+
opencv-python
|
| 4 |
+
qrcode
|
server.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import qrcode as qr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import cv2
|
| 6 |
+
|
| 7 |
+
# build qr code encoder function
|
| 8 |
+
def qr_code_encoder(url, box_size, border_width, fill_color, back_color):
|
| 9 |
+
"""
|
| 10 |
+
Generate a QR code from a given URL.
|
| 11 |
+
Args:
|
| 12 |
+
url: The URL to generate the QR code for.
|
| 13 |
+
fill_color: The color to fill the QR code with.
|
| 14 |
+
back_color: The background color of the QR code.
|
| 15 |
+
Returns:
|
| 16 |
+
The QR code as a numpy array.
|
| 17 |
+
"""
|
| 18 |
+
try:
|
| 19 |
+
qr_code = qr.QRCode(version=1, box_size=box_size, border=border_width)
|
| 20 |
+
qr_code.add_data(url)
|
| 21 |
+
qr_code.make(fit=True)
|
| 22 |
+
img = qr_code.make_image(fill_color=fill_color, back_color=back_color)
|
| 23 |
+
return np.array(img)
|
| 24 |
+
except Exception as e:
|
| 25 |
+
gr.Info("Failed to generate QR code!")
|
| 26 |
+
|
| 27 |
+
# build Gradio MCP frontend
|
| 28 |
+
qr_code_encoder = gr.Interface(fn=qr_code_encoder,
|
| 29 |
+
title="QR Code MCP Server",
|
| 30 |
+
inputs = [gr.Text(label = "URL"),
|
| 31 |
+
gr.Slider(label = "Select Box Size:",minimum=5,maximum = 20,value = 10,step=1),
|
| 32 |
+
gr.Slider(label="Select Border Width:",minimum=1,maximum=10,value=5,step=1),
|
| 33 |
+
gr.Radio(label = "Select Fill Color:",
|
| 34 |
+
choices = ["black","green","blue"],
|
| 35 |
+
value="black"),
|
| 36 |
+
gr.Text(label = "Enter Background Color")],
|
| 37 |
+
outputs = gr.Image(type="pil",label="QR Code"))
|
| 38 |
+
|
| 39 |
+
#
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
qr_code_encoder.launch(mcp_server = True)
|