ariankhalfani commited on
Commit
5550d19
1 Parent(s): 352d663

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -12
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
 
2
 
3
- def generate_script(dataset_code, task, model_size, epochs, batch_size):
4
  # Extract the necessary information from the dataset code
5
  api_key_match = re.search(r'api_key="(.*?)"', dataset_code)
6
  workspace_match = re.search(r'workspace\("([^"]+)"\)', dataset_code)
@@ -107,16 +108,72 @@ if __name__ == "__main__":
107
  """
108
  return script
109
 
110
- # Streamlit interface
111
- st.title("Auto Train Script Generator")
112
- st.write("Generate a YOLOv8 training script using a Roboflow dataset")
 
 
 
113
 
114
- dataset_code = st.text_input("Roboflow Dataset Code", placeholder="Paste your Roboflow dataset code here")
115
- task = st.selectbox("Task", ["Object Detection", "Segmentation"], index=0)
116
- model_size = st.selectbox("Model Size", ["n", "s", "m", "l", "x"], index=0)
117
- epochs = st.selectbox("Epochs", [50, 100, 200, 300, 400, 500], index=3)
118
- batch_size = st.selectbox("Batch Size", [1, 2, 4, 8, 16, 32], index=0)
119
 
120
- if st.button("Generate Script"):
121
- script = generate_script(dataset_code, task, model_size, epochs, batch_size)
122
- st.code(script, language="python")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import re
3
 
4
+ def generate_script_v8(dataset_code, task, model_size, epochs, batch_size):
5
  # Extract the necessary information from the dataset code
6
  api_key_match = re.search(r'api_key="(.*?)"', dataset_code)
7
  workspace_match = re.search(r'workspace\("([^"]+)"\)', dataset_code)
 
108
  """
109
  return script
110
 
111
+ def generate_script_v9(dataset_code, task, model_size, epochs, batch_size):
112
+ # Extract the necessary information from the dataset code
113
+ api_key_match = re.search(r'api_key="(.*?)"', dataset_code)
114
+ workspace_match = re.search(r'workspace\("([^"]+)"\)', dataset_code)
115
+ project_name_match = re.search(r'project\("([^"]+)"\)', dataset_code)
116
+ version_number_match = re.search(r'version\((\d+)\)', dataset_code)
117
 
118
+ if not (api_key_match and workspace_match and project_name_match and version_number_match):
119
+ return "Error: Could not extract necessary information from the dataset code."
 
 
 
120
 
121
+ api_key = api_key_match.group(1)
122
+ workspace = workspace_match.group(1)
123
+ project_name = project_name_match.group(1)
124
+ version_number = int(version_number_match.group(1))
125
+
126
+ # Determine the model name based on the selected size and task
127
+ if task == "Segmentation":
128
+ model_name = f"gelan-c-seg.pt" if model_size == "c" else f"yolov9-{model_size}-seg.pt"
129
+ else:
130
+ model_name = f"yolov9-{model_size}.pt"
131
+
132
+ # Generate the script
133
+ script = f"""
134
+ !pip install roboflow
135
+
136
+ from roboflow import Roboflow
137
+ rf = Roboflow(api_key="{api_key}")
138
+ project = rf.workspace("{workspace}").project("{project_name}")
139
+ version = project.version({version_number})
140
+ dataset = version.download("yolov9")
141
+
142
+ !python train.py \\
143
+ --batch {batch_size} --epochs {epochs} --img 640 --device 0 --min-items 0 --close-mosaic 15 \\
144
+ --data {{dataset.location}}/data.yaml \\
145
+ --weights {{HOME}}/weights/{model_name} \\
146
+ --cfg models/detect/{model_name.split('.')[0]}.yaml \\
147
+ --hyp hyp.scratch-high.yaml
148
+ """
149
+ return script
150
+
151
+ # Streamlit interface
152
+ st.title("Auto Train Script Generator")
153
+ st.write("Generate a YOLO training script using a Roboflow dataset")
154
+
155
+ tab1, tab2 = st.tabs(["YOLOv8", "YOLOv9"])
156
+
157
+ with tab1:
158
+ st.subheader("YOLOv8 Script Generator")
159
+ dataset_code = st.text_input("Roboflow Dataset Code", key="dataset_code_v8", placeholder="Paste your Roboflow dataset code here")
160
+ task = st.selectbox("Task", ["Object Detection", "Segmentation"], index=0, key="task_v8")
161
+ model_size = st.selectbox("Model Size", ["n", "s", "m", "l", "x"], index=0, key="model_size_v8")
162
+ epochs = st.selectbox("Epochs", [50, 100, 200, 300, 400, 500], index=3, key="epochs_v8")
163
+ batch_size = st.selectbox("Batch Size", [1, 2, 4, 8, 16, 32], index=0, key="batch_size_v8")
164
+
165
+ if st.button("Generate YOLOv8 Script"):
166
+ script = generate_script_v8(dataset_code, task, model_size, epochs, batch_size)
167
+ st.code(script, language="python")
168
+
169
+ with tab2:
170
+ st.subheader("YOLOv9 Script Generator")
171
+ dataset_code = st.text_input("Roboflow Dataset Code", key="dataset_code_v9", placeholder="Paste your Roboflow dataset code here")
172
+ task = st.selectbox("Task", ["Object Detection", "Segmentation"], index=0, key="task_v9")
173
+ model_size = st.selectbox("Model Size", ["t", "s", "m", "c", "e"], index=0, key="model_size_v9")
174
+ epochs = st.selectbox("Epochs", [50, 100, 200, 300, 400, 500], index=3, key="epochs_v9")
175
+ batch_size = st.selectbox("Batch Size", [1, 2, 4, 8, 16, 32], index=0, key="batch_size_v9")
176
+
177
+ if st.button("Generate YOLOv9 Script"):
178
+ script = generate_script_v9(dataset_code, task, model_size, epochs, batch_size)
179
+ st.code(script, language="python")