Spaces:
Paused
Paused
File size: 3,191 Bytes
6ca8ec7 b438a34 d30d3eb 5b765e1 f974b65 5b765e1 f974b65 6ca8ec7 5b765e1 6ca8ec7 b438a34 5b765e1 cfad611 b438a34 6fe716c 4d5516b dca4179 9ead2de 4d5516b 9d9c92a 4d5516b 9d9c92a 9ead2de 4d5516b dca4179 4d5516b b438a34 9ead2de b438a34 9d9c92a b438a34 017960d f974b65 b438a34 9d9c92a b438a34 9ead2de 6ca8ec7 9ead2de b438a34 4d5516b 9ead2de e4572ba 1e9ab38 f974b65 1e9ab38 f974b65 6ca8ec7 f974b65 aa47d42 f974b65 aa47d42 b438a34 f974b65 1e9ab38 f974b65 aa47d42 f974b65 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
import dash
from dash import dcc, html, Input, Output, State, callback
import dash_bootstrap_components as dbc
import json
import os
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Disable SSL warnings
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# Create a session that ignores SSL verification
session = requests.Session()
session.verify = False
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:
links = json.load(f)
print(f"Loaded links: {links}") # Debug print
return links
print("JSON file not found") # Debug print
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'},
allow="*",
src=""
)
], 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:
url = link['url']
print(f"Loading URL: {url}")
try:
# Use the session to make a request, ignoring SSL errors
response = session.get(url, verify=False)
response.raise_for_status()
return url
except requests.exceptions.RequestException as e:
print(f"Error loading URL: {e}")
return url # Return the URL even if there's an error
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.") |