Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,11 @@ import gradio as gr
|
|
5 |
import tempfile
|
6 |
import os
|
7 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Function to generate a QR code
|
10 |
def generate_qr(data):
|
@@ -39,6 +44,12 @@ def read_qr(img):
|
|
39 |
|
40 |
return data if data else "No QR code found."
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Custom CSS styling as HTML for dark mode
|
43 |
custom_css = """
|
44 |
<style>
|
@@ -55,8 +66,12 @@ custom_css = """
|
|
55 |
# Gradio interface for generating and reading QR codes
|
56 |
def create_gradio_interface():
|
57 |
# QR Code Generator Interface
|
|
|
|
|
|
|
|
|
58 |
generate_interface = gr.Interface(
|
59 |
-
fn=
|
60 |
inputs=gr.Textbox(placeholder="Enter text or URL here...", label="Data to Encode"),
|
61 |
outputs=gr.Image(label="Generated QR Code"),
|
62 |
title="Generate QR Code",
|
@@ -83,7 +98,7 @@ def create_gradio_interface():
|
|
83 |
gr.HTML(custom_css) # Embed the custom CSS
|
84 |
interface.render()
|
85 |
|
86 |
-
demo.launch(share=True)
|
87 |
|
88 |
# Run the Gradio interface
|
89 |
-
create_gradio_interface()
|
|
|
5 |
import tempfile
|
6 |
import os
|
7 |
import numpy as np
|
8 |
+
from fastapi import FastAPI
|
9 |
+
from fastapi.responses import FileResponse
|
10 |
+
|
11 |
+
# Create a FastAPI app instance for API calls
|
12 |
+
app = FastAPI()
|
13 |
|
14 |
# Function to generate a QR code
|
15 |
def generate_qr(data):
|
|
|
44 |
|
45 |
return data if data else "No QR code found."
|
46 |
|
47 |
+
# API endpoint to download QR code
|
48 |
+
@app.get("/download_qr")
|
49 |
+
def download_qr(data: str):
|
50 |
+
file_path = generate_qr(data)
|
51 |
+
return FileResponse(file_path, media_type="image/png", filename="qrcode.png")
|
52 |
+
|
53 |
# Custom CSS styling as HTML for dark mode
|
54 |
custom_css = """
|
55 |
<style>
|
|
|
66 |
# Gradio interface for generating and reading QR codes
|
67 |
def create_gradio_interface():
|
68 |
# QR Code Generator Interface
|
69 |
+
def generate_and_display_qr(data):
|
70 |
+
file_path = generate_qr(data)
|
71 |
+
return file_path
|
72 |
+
|
73 |
generate_interface = gr.Interface(
|
74 |
+
fn=generate_and_display_qr,
|
75 |
inputs=gr.Textbox(placeholder="Enter text or URL here...", label="Data to Encode"),
|
76 |
outputs=gr.Image(label="Generated QR Code"),
|
77 |
title="Generate QR Code",
|
|
|
98 |
gr.HTML(custom_css) # Embed the custom CSS
|
99 |
interface.render()
|
100 |
|
101 |
+
demo.launch(share=True, server_name="0.0.0.0", server_port=7860)
|
102 |
|
103 |
# Run the Gradio interface
|
104 |
+
create_gradio_interface()
|