Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,22 +5,6 @@ import gradio as gr
|
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
import numpy as np
|
| 8 |
-
from fastapi import FastAPI
|
| 9 |
-
from fastapi.responses import FileResponse
|
| 10 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
-
import threading
|
| 12 |
-
import uvicorn
|
| 13 |
-
|
| 14 |
-
# Create a FastAPI app instance for API calls
|
| 15 |
-
app = FastAPI()
|
| 16 |
-
|
| 17 |
-
# Add CORS middleware to allow external API calls
|
| 18 |
-
app.add_middleware(
|
| 19 |
-
CORSMiddleware,
|
| 20 |
-
allow_origins=["*"],
|
| 21 |
-
allow_methods=["*"],
|
| 22 |
-
allow_headers=["*"],
|
| 23 |
-
)
|
| 24 |
|
| 25 |
# Function to generate a QR code
|
| 26 |
def generate_qr(data):
|
|
@@ -55,12 +39,6 @@ def read_qr(img):
|
|
| 55 |
|
| 56 |
return data if data else "No QR code found."
|
| 57 |
|
| 58 |
-
# API endpoint to download QR code
|
| 59 |
-
@app.get("/download_qr")
|
| 60 |
-
def download_qr(data: str):
|
| 61 |
-
file_path = generate_qr(data)
|
| 62 |
-
return FileResponse(file_path, media_type="image/png", filename="qrcode.png")
|
| 63 |
-
|
| 64 |
# Custom CSS styling as HTML for dark mode
|
| 65 |
custom_css = """
|
| 66 |
<style>
|
|
@@ -105,13 +83,7 @@ def create_gradio_interface():
|
|
| 105 |
gr.HTML(custom_css) # Embed the custom CSS
|
| 106 |
interface.render()
|
| 107 |
|
| 108 |
-
demo.launch(share=True
|
| 109 |
-
|
| 110 |
-
# Function to run FastAPI in a separate thread
|
| 111 |
-
def run_fastapi():
|
| 112 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 113 |
|
| 114 |
-
# Run
|
| 115 |
-
|
| 116 |
-
threading.Thread(target=run_fastapi).start()
|
| 117 |
-
create_gradio_interface()
|
|
|
|
| 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 |
|
| 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>
|
|
|
|
| 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()
|
|
|
|
|
|