Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -110,7 +110,7 @@ def index():
|
|
110 |
|
111 |
@app.route('/generate', methods=['POST'])
|
112 |
def generate_script():
|
113 |
-
#
|
114 |
assembly_info = {
|
115 |
'title': random.choice(titles),
|
116 |
'description': random.choice(descriptions),
|
@@ -124,7 +124,7 @@ def generate_script():
|
|
124 |
'informational_version': random_version()
|
125 |
}
|
126 |
|
127 |
-
#
|
128 |
modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
|
129 |
.replace('<<description>>', assembly_info['description']) \
|
130 |
.replace('<<configuration>>', assembly_info['configuration']) \
|
@@ -144,19 +144,20 @@ def generate_script():
|
|
144 |
with open(script_path, 'w') as file:
|
145 |
file.write(modified_cs)
|
146 |
|
147 |
-
#
|
148 |
-
compile_command = f'
|
149 |
-
|
150 |
-
result = subprocess.run(compile_command, shell=True, check=False)
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
|
156 |
-
|
|
|
157 |
|
158 |
# Provide a link to download the compiled executable
|
159 |
-
return send_file('
|
|
|
160 |
|
161 |
# Start the Flask app
|
162 |
if __name__ == '__main__':
|
|
|
110 |
|
111 |
@app.route('/generate', methods=['POST'])
|
112 |
def generate_script():
|
113 |
+
# Generate the randomized assembly information using meaningful words
|
114 |
assembly_info = {
|
115 |
'title': random.choice(titles),
|
116 |
'description': random.choice(descriptions),
|
|
|
124 |
'informational_version': random_version()
|
125 |
}
|
126 |
|
127 |
+
# Replace placeholders in the base template
|
128 |
modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
|
129 |
.replace('<<description>>', assembly_info['description']) \
|
130 |
.replace('<<configuration>>', assembly_info['configuration']) \
|
|
|
144 |
with open(script_path, 'w') as file:
|
145 |
file.write(modified_cs)
|
146 |
|
147 |
+
# Compile the C# script using csc
|
148 |
+
compile_command = f'csc /target:exe /out:run.exe {script_path}' # Removed unnecessary options
|
149 |
+
process = subprocess.run(compile_command, shell=True, capture_output=True, text=True)
|
|
|
150 |
|
151 |
+
# Log the output and errors for debugging
|
152 |
+
print("Compilation Output:", process.stdout)
|
153 |
+
print("Compilation Error:", process.stderr)
|
154 |
|
155 |
+
if process.returncode != 0:
|
156 |
+
return f"Compilation failed: {process.stderr}", 500
|
157 |
|
158 |
# Provide a link to download the compiled executable
|
159 |
+
return send_file('run.exe', as_attachment=True)
|
160 |
+
|
161 |
|
162 |
# Start the Flask app
|
163 |
if __name__ == '__main__':
|