Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,30 +1,74 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
import
|
4 |
-
from torchvision import transforms
|
5 |
|
6 |
-
|
7 |
-
response = requests.get("https://git.io/JJkYN")
|
8 |
-
labels = response.text.split("\n")
|
9 |
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
with torch.no_grad():
|
14 |
-
prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
|
15 |
-
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
16 |
-
return confidences
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
inputs=gr.Image(type="pil"),
|
23 |
-
outputs=gr.Label(num_top_classes=3),
|
24 |
-
)
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, send_from_directory, render_template_string
|
2 |
+
import os
|
3 |
+
import subprocess
|
|
|
4 |
|
5 |
+
app = Flask(__name__)
|
|
|
|
|
6 |
|
7 |
+
# Directory to save uploaded ISS files and generated EXEs
|
8 |
+
UPLOAD_FOLDER = 'uploads'
|
9 |
+
COMPILE_FOLDER = 'compiled'
|
10 |
|
11 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
12 |
+
os.makedirs(COMPILE_FOLDER, exist_ok=True)
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# HTML template for the interface
|
15 |
+
html_template = """
|
16 |
+
<!DOCTYPE html>
|
17 |
+
<html lang="en">
|
18 |
+
<head>
|
19 |
+
<meta charset="UTF-8">
|
20 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
21 |
+
<title>Inno Setup Compiler</title>
|
22 |
+
</head>
|
23 |
+
<body>
|
24 |
+
<h1>Upload your .iss file to compile</h1>
|
25 |
+
<form action="/upload" method="post" enctype="multipart/form-data">
|
26 |
+
<input type="file" name="iss_file" accept=".iss" required>
|
27 |
+
<button type="submit">Upload and Compile</button>
|
28 |
+
</form>
|
29 |
+
<pre>{{ logs }}</pre>
|
30 |
+
</body>
|
31 |
+
</html>
|
32 |
+
"""
|
33 |
|
34 |
+
@app.route('/')
|
35 |
+
def index():
|
36 |
+
return render_template_string(html_template, logs="")
|
|
|
|
|
|
|
37 |
|
38 |
+
@app.route('/upload', methods=['POST'])
|
39 |
+
def upload_iss():
|
40 |
+
if 'iss_file' not in request.files:
|
41 |
+
return "No file part"
|
42 |
+
|
43 |
+
file = request.files['iss_file']
|
44 |
+
|
45 |
+
if file.filename == '':
|
46 |
+
return "No selected file"
|
47 |
+
|
48 |
+
# Save the ISS file
|
49 |
+
iss_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
50 |
+
file.save(iss_path)
|
51 |
+
|
52 |
+
# Compile the ISS file using Inno Setup
|
53 |
+
exe_name = file.filename.replace('.iss', '.exe')
|
54 |
+
exe_path = os.path.join(COMPILE_FOLDER, exe_name)
|
55 |
+
|
56 |
+
# Command to run Inno Setup
|
57 |
+
compile_command = f'inno-setup-compiler "{iss_path}"'
|
58 |
|
59 |
+
# Run the command and capture logs
|
60 |
+
result = subprocess.run(compile_command, shell=True, capture_output=True, text=True)
|
61 |
+
|
62 |
+
logs = result.stdout + result.stderr
|
63 |
+
|
64 |
+
if result.returncode == 0:
|
65 |
+
return f'Compilation successful! Download <a href="/download/{exe_name}">here</a>'
|
66 |
+
else:
|
67 |
+
return f'Compilation failed: <pre>{logs}</pre>'
|
68 |
|
69 |
+
@app.route('/download/<filename>')
|
70 |
+
def download_file(filename):
|
71 |
+
return send_from_directory(COMPILE_FOLDER, filename)
|
72 |
+
|
73 |
+
if __name__ == '__main__':
|
74 |
+
app.run(host='0.0.0.0', port=7860, debug=True)
|