File size: 1,906 Bytes
9dab839
7d573e7
 
9dab839
7d573e7
9dab839
 
7d573e7
 
9dab839
7d573e7
9dab839
 
7d573e7
9dab839
 
 
 
 
 
7d573e7
f98794a
9dab839
f98794a
9dab839
 
f98794a
 
9dab839
 
7d573e7
9dab839
 
 
 
7d573e7
 
 
 
 
 
 
 
 
 
9dab839
7d573e7
 
9dab839
7d573e7
 
9dab839
7d573e7
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
from flask import Flask, render_template_string
import gradio as gr

# Initialize Flask app
app = Flask(__name__)

# Install and upgrade gradio if not already installed
os.system("pip install --upgrade gradio")

# HTML template with metadata
html_template = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Twitter Card metadata -->
    <meta name="twitter:card" content="player">
    <meta name="twitter:site" content="@broadfield-dev">
    <meta name="twitter:title" content="Gradio Sketch Demo">
    <meta name="twitter:description" content="No-Code Gradio App Builder - Demo">
    <meta name="twitter:image" content="https://your-domain.com/preview-image.jpg">
    <meta name="twitter:player" content="https://broadfield-dev-gradio-sketch.hf.space">
    <meta name="twitter:player:width" content="480">
    <meta name="twitter:player:height" content="480">
    <meta name="twitter:player:stream" content="https://broadfield-dev-gradio-sketch.hf.space">
    <title>Gradio Sketch Demo</title>
</head>
<body>
    {{ gradio_ui|safe }}
</body>
</html>
"""

# Define the Gradio interface
def create_gradio_interface():
    with gr.Blocks(title="Gradio Sketch Demo") as demo:
        gr.Markdown("# Gradio Sketch Demo")
        sketchpad = gr.Sketchpad()
        output = gr.Image()
        sketchpad.change(fn=lambda x: x, inputs=sketchpad, outputs=output)
    return demo

# Flask route
@app.route('/')
def index():
    gradio_app = create_gradio_interface()
    # Launch Gradio and get its HTML content
    gradio_html = gradio_app.launch(prevent_thread_lock=True, show_api=False, inline=True)
    return render_template_string(html_template, gradio_ui=gradio_html)

if __name__ == "__main__":
    # For Hugging Face Spaces, use port 7860
    app.run(host="0.0.0.0", port=7860, debug=False)