Upload test_multi_lora.py with huggingface_hub
Browse files- test_multi_lora.py +25 -7
test_multi_lora.py
CHANGED
|
@@ -239,12 +239,16 @@ def main():
|
|
| 239 |
summary = json.dumps(results, indent=2, default=str, ensure_ascii=False)
|
| 240 |
print(summary)
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
# 결과를 HF repo에 업로드
|
| 243 |
try:
|
| 244 |
from huggingface_hub import HfApi
|
| 245 |
-
result_path = "/tmp/test_results.json"
|
| 246 |
-
with open(result_path, "w") as f:
|
| 247 |
-
f.write(summary)
|
| 248 |
api = HfApi()
|
| 249 |
api.upload_file(
|
| 250 |
path_or_fileobj=result_path,
|
|
@@ -256,10 +260,24 @@ def main():
|
|
| 256 |
except Exception as e:
|
| 257 |
print(f"\nFailed to upload results: {e}")
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
|
| 265 |
if __name__ == "__main__":
|
|
|
|
| 239 |
summary = json.dumps(results, indent=2, default=str, ensure_ascii=False)
|
| 240 |
print(summary)
|
| 241 |
|
| 242 |
+
sys.stdout.flush()
|
| 243 |
+
|
| 244 |
+
# 결과를 파일로 저장
|
| 245 |
+
result_path = "/tmp/test_results.json"
|
| 246 |
+
with open(result_path, "w") as f:
|
| 247 |
+
f.write(summary)
|
| 248 |
+
|
| 249 |
# 결과를 HF repo에 업로드
|
| 250 |
try:
|
| 251 |
from huggingface_hub import HfApi
|
|
|
|
|
|
|
|
|
|
| 252 |
api = HfApi()
|
| 253 |
api.upload_file(
|
| 254 |
path_or_fileobj=result_path,
|
|
|
|
| 260 |
except Exception as e:
|
| 261 |
print(f"\nFailed to upload results: {e}")
|
| 262 |
|
| 263 |
+
sys.stdout.flush()
|
| 264 |
+
|
| 265 |
+
# 간단한 HTTP 서버로 Space RUNNING 상태 유지 + 결과 제공
|
| 266 |
+
print("\nTest complete. Starting HTTP server on port 7860...")
|
| 267 |
+
from http.server import HTTPServer, BaseHTTPRequestHandler
|
| 268 |
+
|
| 269 |
+
class ResultHandler(BaseHTTPRequestHandler):
|
| 270 |
+
def do_GET(self):
|
| 271 |
+
self.send_response(200)
|
| 272 |
+
self.send_header("Content-Type", "application/json")
|
| 273 |
+
self.end_headers()
|
| 274 |
+
with open(result_path, "rb") as f:
|
| 275 |
+
self.wfile.write(f.read())
|
| 276 |
+
def log_message(self, format, *args):
|
| 277 |
+
pass # suppress access logs
|
| 278 |
+
|
| 279 |
+
server = HTTPServer(("0.0.0.0", 7860), ResultHandler)
|
| 280 |
+
server.serve_forever()
|
| 281 |
|
| 282 |
|
| 283 |
if __name__ == "__main__":
|