Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,10 +7,19 @@ 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):
|
16 |
qr = qrcode.QRCode(
|
@@ -66,12 +75,8 @@ custom_css = """
|
|
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=
|
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,7 +103,7 @@ def create_gradio_interface():
|
|
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()
|
|
|
7 |
import numpy as np
|
8 |
from fastapi import FastAPI
|
9 |
from fastapi.responses import FileResponse
|
10 |
+
from fastapi.middleware.cors import CORSMiddleware
|
11 |
|
12 |
# Create a FastAPI app instance for API calls
|
13 |
app = FastAPI()
|
14 |
|
15 |
+
# Add CORS middleware to allow external API calls
|
16 |
+
app.add_middleware(
|
17 |
+
CORSMiddleware,
|
18 |
+
allow_origins=["*"],
|
19 |
+
allow_methods=["*"],
|
20 |
+
allow_headers=["*"],
|
21 |
+
)
|
22 |
+
|
23 |
# Function to generate a QR code
|
24 |
def generate_qr(data):
|
25 |
qr = qrcode.QRCode(
|
|
|
75 |
# Gradio interface for generating and reading QR codes
|
76 |
def create_gradio_interface():
|
77 |
# QR Code Generator Interface
|
|
|
|
|
|
|
|
|
78 |
generate_interface = gr.Interface(
|
79 |
+
fn=generate_qr,
|
80 |
inputs=gr.Textbox(placeholder="Enter text or URL here...", label="Data to Encode"),
|
81 |
outputs=gr.Image(label="Generated QR Code"),
|
82 |
title="Generate QR Code",
|
|
|
103 |
gr.HTML(custom_css) # Embed the custom CSS
|
104 |
interface.render()
|
105 |
|
106 |
+
demo.launch(share=True, server_name="0.0.0.0", server_port=7860, app=app)
|
107 |
|
108 |
# Run the Gradio interface
|
109 |
create_gradio_interface()
|