Spaces:
Paused
Paused
File size: 2,753 Bytes
6ca8ec7 b438a34 d30d3eb 5b765e1 6ca8ec7 5b765e1 6ca8ec7 b438a34 5b765e1 b438a34 6fe716c 4d5516b dca4179 9ead2de 4d5516b 9d9c92a 4d5516b 9d9c92a 9ead2de 4d5516b dca4179 4d5516b b438a34 9ead2de b438a34 9d9c92a b438a34 9d9c92a b438a34 9ead2de 6ca8ec7 9ead2de b438a34 4d5516b 9ead2de e4572ba 6ca8ec7 aa47d42 6ca8ec7 aa47d42 6ca8ec7 aa47d42 6ca8ec7 aa47d42 6ca8ec7 aa47d42 b438a34 aa47d42 b438a34 aa47d42 f46a246 5b765e1 f46a246 |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import dash
from dash import dcc, html, Input, Output, State, callback
import dash_bootstrap_components as dbc
import json
import os
import requests
from urllib3.exceptions import InsecureRequestWarning
# Disable SSL warnings
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
JSON_FILE = 'app.json'
def load_links():
if os.path.exists(JSON_FILE):
with open(JSON_FILE, 'r') as f:
return json.load(f)
return []
def generate_url_list(links):
url_list = [
dbc.ListGroupItem(
dbc.Button(
link['name'],
id={'type': 'url-button', 'index': link['id']},
color="link",
className="text-left w-100"
),
className="p-0"
)
for link in links
]
print(f"Generated URL list: {url_list}") # Debug print
return url_list
app.layout = dbc.Container([
dbc.Row([
dbc.Col([
html.H2("AI Apps", className="mt-3 mb-4"),
html.Div(id='url-list'),
], width=2, className="bg-light-grey p-3"),
dbc.Col([
html.Iframe(
id='content-iframe',
style={'width': '100%', 'height': '800px'},
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-downloads",
allow="fullscreen; geolocation; microphone; camera; midi; encrypted-media; autoplay",
referrerPolicy="no-referrer"
)
], width=10, className="bg-white")
])
], fluid=True)
@callback(
Output('url-list', 'children'),
Input('url-list', 'id')
)
def update_url_list(_):
links = load_links()
url_list = generate_url_list(links)
return url_list
@callback(
Output('content-iframe', 'src'),
Input({'type': 'url-button', 'index': dash.ALL}, 'n_clicks'),
prevent_initial_call=True
)
def update_iframe(*n_clicks):
ctx = dash.callback_context
if not ctx.triggered:
print("No button clicked")
return dash.no_update
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
clicked_id = eval(button_id)['index']
print(f"Button clicked: {clicked_id}")
links = load_links()
for link in links:
if link['id'] == clicked_id:
print(f"Loading URL: {link['url']}")
return link['url']
print("No matching URL found")
return dash.no_update
if __name__ == '__main__':
print("Starting the Dash application...")
print(f"JSON file location: {os.path.abspath(JSON_FILE)}")
app.run(debug=True, host='0.0.0.0', port=7860)
print("Dash application has finished running.") |