broadfield-dev commited on
Commit
b1142f6
·
verified ·
1 Parent(s): e4dda21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -41
app.py CHANGED
@@ -1,18 +1,7 @@
1
  import os
2
- from flask import Flask, render_template_string
3
  import gradio as gr
4
-
5
- # Initialize Flask app
6
- app = Flask(__name__)
7
-
8
- # Install and upgrade gradio if not already installed
9
  os.system("pip install --upgrade gradio")
10
-
11
- # HTML template with metadata
12
- html_template = """
13
- <!DOCTYPE html>
14
- <html lang="en">
15
- <head>
16
  <meta charset="UTF-8">
17
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
18
  <!-- Twitter Card metadata -->
@@ -26,33 +15,9 @@ html_template = """
26
  <meta name="twitter:player:height" content="480">
27
  <meta name="twitter:player:stream" content="https://broadfield-dev-gradio-sketch.hf.space">
28
  <title>Gradio Sketch Demo</title>
29
- {{ gradio_css|safe }}
30
- </head>
31
- <body>
32
- {{ gradio_ui|safe }}
33
- </body>
34
- </html>
35
  """
36
-
37
- # Define the Gradio interface
38
- def create_gradio_interface():
39
- with gr.Blocks(title="Gradio Sketch Demo") as demo:
40
- gr.Markdown("# Gradio Sketch Demo")
41
- sketchpad = gr.Sketchpad()
42
- output = gr.Image()
43
- sketchpad.change(fn=lambda x: x, inputs=sketchpad, outputs=output)
44
- return demo
45
-
46
- # Flask route
47
- @app.route('/')
48
- def index():
49
- gradio_app = create_gradio_interface()
50
- # Get the Gradio UI as HTML without launching a separate server
51
- gradio_html = gradio_app.blocks().to_html()
52
- # Include Gradio CSS (optional, for styling)
53
- gradio_css = '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gradio/dist/gradio.css">'
54
- return render_template_string(html_template, gradio_ui=gradio_html, gradio_css=gradio_css)
55
-
56
- if __name__ == "__main__":
57
- # For Hugging Face Spaces, use port 7860 for Flask
58
- app.run(host="0.0.0.0", port=7860, debug=False)
 
1
  import os
 
2
  import gradio as gr
 
 
 
 
 
3
  os.system("pip install --upgrade gradio")
4
+ head = """
 
 
 
 
 
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
  <!-- Twitter Card metadata -->
 
15
  <meta name="twitter:player:height" content="480">
16
  <meta name="twitter:player:stream" content="https://broadfield-dev-gradio-sketch.hf.space">
17
  <title>Gradio Sketch Demo</title>
 
 
 
 
 
 
18
  """
19
+ def demo():
20
+ os.system("gradio sketch")
21
+ with gr.Blocks(head=head) as app:
22
+ app.load(demo,None,None)
23
+ app.launch()