luet commited on
Commit
f24d252
·
1 Parent(s): 1ae7994
Files changed (2) hide show
  1. app.py +78 -0
  2. models.json +0 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import os
4
+
5
+ # File to store model data
6
+ MODEL_FILE = "models.json"
7
+
8
+ # Load existing data or create a new file if it doesn't exist
9
+ def load_models():
10
+ if os.path.exists(MODEL_FILE):
11
+ with open(MODEL_FILE, "r") as f:
12
+ return json.load(f)
13
+ return []
14
+
15
+ # Save data to the JSON file
16
+ 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
+ output = "### List of AI Models:\n\n"
26
+ for idx, model in enumerate(models):
27
+ output += f"**{idx + 1}. {model['name']}**\n"
28
+ output += f"- **Description**: {model['description']}\n"
29
+ output += f"- **Year**: {model['year']}\n"
30
+ output += "\n"
31
+ return output
32
+
33
+ # Function to add a new model
34
+ def add_model(name, description, year):
35
+ models = load_models()
36
+ models.append({"name": name, "description": description, "year": year})
37
+ save_models(models)
38
+ return "Model added successfully!", display_models()
39
+
40
+ # Function to edit an existing model
41
+ def edit_model(index, name, description, year):
42
+ models = load_models()
43
+ if index < 1 or index > len(models):
44
+ return "Invalid index. Please provide a valid model number.", display_models()
45
+ models[index - 1] = {"name": name, "description": description, "year": year}
46
+ save_models(models)
47
+ return "Model updated successfully!", display_models()
48
+
49
+ # Gradio interface
50
+ with gr.Blocks() as app:
51
+ gr.Markdown("# AI Model Repository\n\nAdd, view, and edit AI models contributed by the community.")
52
+
53
+ with gr.Tab("View Models"):
54
+ view_button = gr.Button("Refresh List")
55
+ view_output = gr.Markdown(display_models())
56
+ view_button.click(display_models, outputs=view_output)
57
+
58
+ with gr.Tab("Add Model"):
59
+ with gr.Row():
60
+ name_input = gr.Textbox(label="Model Name", placeholder="Enter model name")
61
+ year_input = gr.Textbox(label="Publication Year", placeholder="Enter year of publication")
62
+ description_input = gr.Textbox(label="Description", placeholder="Enter a short description")
63
+ add_button = gr.Button("Add Model")
64
+ add_output = gr.Markdown()
65
+ add_button.click(add_model, inputs=[name_input, description_input, year_input], outputs=[add_output, view_output])
66
+
67
+ with gr.Tab("Edit Model"):
68
+ edit_index = gr.Number(label="Model Number", precision=0)
69
+ with gr.Row():
70
+ edit_name = gr.Textbox(label="New Model Name", placeholder="Enter new model name")
71
+ edit_year = gr.Textbox(label="New Publication Year", placeholder="Enter new year of publication")
72
+ edit_description = gr.Textbox(label="New Description", placeholder="Enter new description")
73
+ edit_button = gr.Button("Edit Model")
74
+ edit_output = gr.Markdown()
75
+ edit_button.click(edit_model, inputs=[edit_index, edit_name, edit_description, edit_year], outputs=[edit_output, view_output])
76
+
77
+ # Run the app
78
+ app.launch()
models.json ADDED
File without changes