Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import qrcode
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
|
| 5 |
+
# 🔳 Generate QR Code
|
| 6 |
+
def generate_qr(text):
|
| 7 |
+
if not text:
|
| 8 |
+
return None
|
| 9 |
+
|
| 10 |
+
qr = qrcode.make(text)
|
| 11 |
+
|
| 12 |
+
buffer = BytesIO()
|
| 13 |
+
qr.save(buffer, format="PNG")
|
| 14 |
+
buffer.seek(0)
|
| 15 |
+
|
| 16 |
+
return buffer
|
| 17 |
+
|
| 18 |
+
# 🎨 Modern CSS
|
| 19 |
+
css = """
|
| 20 |
+
body {
|
| 21 |
+
background: linear-gradient(135deg, #1e3c72, #2a5298);
|
| 22 |
+
font-family: 'Poppins', sans-serif;
|
| 23 |
+
color: white;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
h1 {
|
| 27 |
+
text-align: center;
|
| 28 |
+
font-size: 40px;
|
| 29 |
+
background: linear-gradient(90deg, #00c6ff, #0072ff);
|
| 30 |
+
-webkit-background-clip: text;
|
| 31 |
+
-webkit-text-fill-color: transparent;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.qr-box {
|
| 35 |
+
padding: 20px;
|
| 36 |
+
border-radius: 15px;
|
| 37 |
+
background: rgba(255,255,255,0.1);
|
| 38 |
+
backdrop-filter: blur(10px);
|
| 39 |
+
text-align: center;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
button {
|
| 43 |
+
background: linear-gradient(90deg, #ff512f, #dd2476);
|
| 44 |
+
border: none;
|
| 45 |
+
border-radius: 10px;
|
| 46 |
+
padding: 10px;
|
| 47 |
+
color: white;
|
| 48 |
+
font-weight: bold;
|
| 49 |
+
transition: 0.3s;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
button:hover {
|
| 53 |
+
transform: scale(1.05);
|
| 54 |
+
}
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
# 🧠 UI
|
| 58 |
+
with gr.Blocks() as demo:
|
| 59 |
+
gr.Markdown("# 🔳 QR Code Generator")
|
| 60 |
+
|
| 61 |
+
gr.Markdown("Enter any text, URL, or data to generate a QR code")
|
| 62 |
+
|
| 63 |
+
text_input = gr.Textbox(
|
| 64 |
+
placeholder="Enter text or URL...",
|
| 65 |
+
label="Input Data"
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
generate_btn = gr.Button("Generate QR")
|
| 69 |
+
|
| 70 |
+
qr_output = gr.Image(type="pil", label="Your QR Code", elem_classes="qr-box")
|
| 71 |
+
|
| 72 |
+
# Event
|
| 73 |
+
generate_btn.click(
|
| 74 |
+
fn=generate_qr,
|
| 75 |
+
inputs=text_input,
|
| 76 |
+
outputs=qr_output
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# 🚀 Launch (Gradio 6 correct way)
|
| 80 |
+
demo.launch(css=css)
|