Linn Bedroc
commited on
Commit
•
469ab8d
1
Parent(s):
1e9f296
Added hacky local env keys export
Browse files- server.cpp +9 -37
server.cpp
CHANGED
@@ -12,9 +12,6 @@
|
|
12 |
#include <crow.h>
|
13 |
#include <ranges>
|
14 |
#include "threadpool.h"
|
15 |
-
#include <aws/core/Aws.h>
|
16 |
-
#include <aws/s3/S3Client.h>
|
17 |
-
#include <aws/s3/model/PutObjectRequest.h>
|
18 |
#include <sstream>
|
19 |
#define CROW_MAIN
|
20 |
|
@@ -81,35 +78,6 @@ constexpr auto q_to_v(queue<T> qcopy){
|
|
81 |
return v;
|
82 |
}
|
83 |
|
84 |
-
constexpr auto stdfopts = std::ios_base::in | std::ios_base::binary;
|
85 |
-
static inline auto awssave(){
|
86 |
-
auto options = make_shared<Aws::SDKOptions>();
|
87 |
-
Aws::InitAPI(*options);
|
88 |
-
Aws::Client::ClientConfiguration clientConfig;
|
89 |
-
std::shared_ptr<Aws::S3::S3Client> s3_client( new Aws::S3::S3Client(clientConfig)
|
90 |
-
, [=](Aws::S3::S3Client* c){
|
91 |
-
Aws::ShutdownAPI(*options);
|
92 |
-
delete c;
|
93 |
-
});
|
94 |
-
return [=](const std::string& id){
|
95 |
-
Aws::S3::Model::PutObjectRequest request;
|
96 |
-
request.SetBucket("models.webaverse.com");
|
97 |
-
request.SetKey(id);
|
98 |
-
if(auto in = Aws::MakeShared<Aws::FStream>("a", "model.glb", stdfopts); *in){
|
99 |
-
request.SetBody(in);
|
100 |
-
auto outcome = s3_client->PutObject(request);
|
101 |
-
if(outcome.IsSuccess())
|
102 |
-
std::cout << "Added '" << id << "' to bucket 'models.webaverse.com'\n";
|
103 |
-
else
|
104 |
-
std::cerr << "AWS S3 Error: " << outcome.GetError().GetMessage() << "\n";
|
105 |
-
return outcome.IsSuccess();
|
106 |
-
} else {
|
107 |
-
std::cerr << "No such file: model.glb\n";
|
108 |
-
return false;
|
109 |
-
}
|
110 |
-
};
|
111 |
-
}
|
112 |
-
|
113 |
int main(){
|
114 |
crow::SimpleApp app;
|
115 |
typedef std::array<string, 2> guy;
|
@@ -147,7 +115,10 @@ int main(){
|
|
147 |
CROW_LOG_INFO << "Launched training for prompt: " + prompt;
|
148 |
run("rm -rf trial/checkpoints/*");
|
149 |
run(train(prompt));
|
150 |
-
CROW_LOG_INFO << run(
|
|
|
|
|
|
|
151 |
run("rm model.glb");
|
152 |
CROW_LOG_INFO << "Finished training for prompt: " + prompt;
|
153 |
poppe();
|
@@ -161,13 +132,14 @@ int main(){
|
|
161 |
CROW_LOG_INFO << name << " queued with prompt: " << prompt;
|
162 |
};
|
163 |
|
164 |
-
CROW_ROUTE(app, "/create
|
165 |
-
.methods("GET"_method, "POST"_method)([=](const crow::request& req
|
166 |
-
|
167 |
-
if(auto id = uid(prompt); prompt.empty()){
|
168 |
CROW_LOG_INFO << "No prompt specified";
|
169 |
return "Error: Can't train a NeRF without a prompt!";
|
170 |
} else {
|
|
|
|
|
171 |
if(auto r = check_queue(id); r < 0){
|
172 |
enqueue({id, prompt});
|
173 |
pool->enqueue(training_loop);
|
|
|
12 |
#include <crow.h>
|
13 |
#include <ranges>
|
14 |
#include "threadpool.h"
|
|
|
|
|
|
|
15 |
#include <sstream>
|
16 |
#define CROW_MAIN
|
17 |
|
|
|
78 |
return v;
|
79 |
}
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
int main(){
|
82 |
crow::SimpleApp app;
|
83 |
typedef std::array<string, 2> guy;
|
|
|
115 |
CROW_LOG_INFO << "Launched training for prompt: " + prompt;
|
116 |
run("rm -rf trial/checkpoints/*");
|
117 |
run(train(prompt));
|
118 |
+
CROW_LOG_INFO << run(
|
119 |
+
string( "export AWS_SECRET_ACCESS_KEY=$(cat .env.local | grep AWS_SECRET | cut -d \"\"\" -f 2) ")
|
120 |
+
+ "&& export AWS_ACCESS_KEY=$(cat .env.local | grep AWS_ACCESS | cut -d \"\"\" -f 2) "
|
121 |
+
+ "&& aws s3 cp model.glb s3://models.webaverse.com/" + id + ".glb");
|
122 |
run("rm model.glb");
|
123 |
CROW_LOG_INFO << "Finished training for prompt: " + prompt;
|
124 |
poppe();
|
|
|
132 |
CROW_LOG_INFO << name << " queued with prompt: " << prompt;
|
133 |
};
|
134 |
|
135 |
+
CROW_ROUTE(app, "/create")
|
136 |
+
.methods("GET"_method, "POST"_method)([=](const crow::request& req) -> string {
|
137 |
+
if(auto prompt = req.url_params.get("prompt"); prompt == nullptr){
|
|
|
138 |
CROW_LOG_INFO << "No prompt specified";
|
139 |
return "Error: Can't train a NeRF without a prompt!";
|
140 |
} else {
|
141 |
+
CROW_LOG_INFO << prompt << " commissioned";
|
142 |
+
auto id = uid(prompt);
|
143 |
if(auto r = check_queue(id); r < 0){
|
144 |
enqueue({id, prompt});
|
145 |
pool->enqueue(training_loop);
|