luet commited on
Commit
d637e02
·
1 Parent(s): a016519

Improved UI

Browse files
Files changed (1) hide show
  1. app.py +55 -10
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import json
3
  import os
 
4
 
5
  # File to store model data
6
  MODEL_FILE = "models.json"
@@ -17,21 +18,43 @@ def save_models(models):
17
  with open(MODEL_FILE, "w") as f:
18
  json.dump(models, f, indent=4)
19
 
20
- # Function to display all models
21
- def display_models():
 
 
 
 
 
 
 
 
22
  models = load_models()
23
  if not models:
24
  return "No models have been added yet."
 
 
 
 
 
 
 
 
 
 
25
  models = sorted(models, key=lambda x: x['dateOfRelease']) # Sort by release date
26
- output = "" # Prepare HTML output for timeline
 
 
27
  for model in models:
28
- output += "<div style='border: 1px solid #ccc; border-radius: 10px; padding: 10px; margin: 10px;'>"
29
- output += f"<h3>{model['name']} ({model['dateOfRelease']})</h3>"
 
30
  output += f"<p><strong>Description:</strong> {model['description']}</p>"
31
  output += f"<p><strong>Developer:</strong> {model.get('developer', 'Unknown')}</p>"
32
  output += f"<p><strong>Use Case:</strong> {model.get('use_case', 'General')}</p>"
33
  output += f"<p><strong>Impact:</strong> {model.get('impact', 'Not specified')}</p>"
34
  output += "</div>"
 
35
  return output
36
 
37
  # Function to add a new model
@@ -65,13 +88,35 @@ def edit_model(index, name, description, dateOfRelease, developer, use_case, imp
65
  return "Model updated successfully!", display_models()
66
 
67
  # Gradio interface
68
- with gr.Blocks() as app:
 
 
 
 
 
 
 
 
 
 
 
 
69
  gr.Markdown("# AI Timeline\n\nVisualize the development of AI models through an interactive timeline.")
70
 
71
  with gr.Tab("View Timeline"):
72
- view_button = gr.Button("Refresh Timeline")
73
- view_output = gr.HTML(display_models())
74
- view_button.click(display_models, outputs=view_output)
 
 
 
 
 
 
 
 
 
 
75
 
76
  with gr.Tab("Add Model"):
77
  with gr.Row():
@@ -107,4 +152,4 @@ with gr.Blocks() as app:
107
  )
108
 
109
  # Run the app
110
- app.launch()
 
1
  import gradio as gr
2
  import json
3
  import os
4
+ from datetime import datetime
5
 
6
  # File to store model data
7
  MODEL_FILE = "models.json"
 
18
  with open(MODEL_FILE, "w") as f:
19
  json.dump(models, f, indent=4)
20
 
21
+ # Helper function to calculate time differences between releases
22
+ def calculate_time_difference(models):
23
+ for i in range(1, len(models)):
24
+ prev_date = datetime.strptime(models[i - 1]['dateOfRelease'], "%Y-%m-%d")
25
+ curr_date = datetime.strptime(models[i]['dateOfRelease'], "%Y-%m-%d")
26
+ models[i]['time_difference'] = (curr_date - prev_date).days
27
+ return models
28
+
29
+ # Function to display all models with optional filters
30
+ def display_models(developer=None, use_case=None, year_range=None):
31
  models = load_models()
32
  if not models:
33
  return "No models have been added yet."
34
+
35
+ # Apply filters if provided
36
+ if developer:
37
+ models = [m for m in models if m.get('developer') == developer]
38
+ if use_case:
39
+ models = [m for m in models if m.get('use_case') == use_case]
40
+ if year_range:
41
+ start_year, end_year = year_range
42
+ models = [m for m in models if start_year <= int(m['dateOfRelease'][:4]) <= end_year]
43
+
44
  models = sorted(models, key=lambda x: x['dateOfRelease']) # Sort by release date
45
+ models = calculate_time_difference(models) # Calculate time differences
46
+
47
+ output = "<div style='display: flex; flex-direction: column; align-items: flex-start; gap: 20px;'>"
48
  for model in models:
49
+ time_gap = model.get('time_difference', 0) * 2 # Scale time gap for visualization
50
+ output += f"<div style='margin-top: {time_gap}px; border: 1px solid #ccc; border-radius: 10px; padding: 10px; width: 90%; background: linear-gradient(135deg, #f9f9f9, #e9e9e9); box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);'>"
51
+ output += f"<h3 style='color: #2d89ef;'>{model['name']} ({model['dateOfRelease']})</h3>"
52
  output += f"<p><strong>Description:</strong> {model['description']}</p>"
53
  output += f"<p><strong>Developer:</strong> {model.get('developer', 'Unknown')}</p>"
54
  output += f"<p><strong>Use Case:</strong> {model.get('use_case', 'General')}</p>"
55
  output += f"<p><strong>Impact:</strong> {model.get('impact', 'Not specified')}</p>"
56
  output += "</div>"
57
+ output += "</div>"
58
  return output
59
 
60
  # Function to add a new model
 
88
  return "Model updated successfully!", display_models()
89
 
90
  # Gradio interface
91
+ with gr.Blocks(css="""
92
+ body {
93
+ font-family: 'Arial', sans-serif;
94
+ background-color: #f4f4f4;
95
+ margin: 0;
96
+ padding: 0;
97
+ }
98
+ .gradio-container {
99
+ width: 80%;
100
+ margin: auto;
101
+ padding: 20px;
102
+ }
103
+ """) as app:
104
  gr.Markdown("# AI Timeline\n\nVisualize the development of AI models through an interactive timeline.")
105
 
106
  with gr.Tab("View Timeline"):
107
+ with gr.Row():
108
+ developer_filter = gr.Dropdown(label="Filter by Developer", choices=["All"] + list(set([m['developer'] for m in load_models()])), value="All")
109
+ use_case_filter = gr.Dropdown(label="Filter by Use Case", choices=["All"] + list(set([m['use_case'] for m in load_models()])), value="All")
110
+ year_range_filter = gr.Slider(label="Filter by Year Range", minimum=2000, maximum=2025, value=(2000, 2025), step=1)
111
+ filter_button = gr.Button("Apply Filters")
112
+ view_output = gr.HTML()
113
+
114
+ def apply_filters(developer, use_case, year_range):
115
+ dev = None if developer == "All" else developer
116
+ use = None if use_case == "All" else use_case
117
+ return display_models(developer=dev, use_case=use, year_range=year_range)
118
+
119
+ filter_button.click(apply_filters, inputs=[developer_filter, use_case_filter, year_range_filter], outputs=view_output)
120
 
121
  with gr.Tab("Add Model"):
122
  with gr.Row():
 
152
  )
153
 
154
  # Run the app
155
+ app.launch()