Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ from transformers import GPT2LMHeadModel, GPT2Tokenizer, Trainer, TrainingArgume
|
|
5 |
from datasets import load_dataset, concatenate_datasets
|
6 |
from huggingface_hub import login
|
7 |
import time
|
|
|
|
|
8 |
|
9 |
load_dotenv()
|
10 |
login(token=os.getenv('HUGGINGFACE_TOKEN'))
|
@@ -53,6 +55,12 @@ trainer = Trainer(
|
|
53 |
train_dataset=tokenized_dataset,
|
54 |
)
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
@spaces.gpu
|
57 |
def run_training():
|
58 |
while True:
|
@@ -65,7 +73,7 @@ def run_training():
|
|
65 |
print(f"Error durante el entrenamiento: {e}. Reiniciando el proceso de entrenamiento...")
|
66 |
time.sleep(10)
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
5 |
from datasets import load_dataset, concatenate_datasets
|
6 |
from huggingface_hub import login
|
7 |
import time
|
8 |
+
import uvicorn
|
9 |
+
from fastapi import FastAPI
|
10 |
|
11 |
load_dotenv()
|
12 |
login(token=os.getenv('HUGGINGFACE_TOKEN'))
|
|
|
55 |
train_dataset=tokenized_dataset,
|
56 |
)
|
57 |
|
58 |
+
app = FastAPI()
|
59 |
+
|
60 |
+
@app.get("/")
|
61 |
+
async def root():
|
62 |
+
return {"message": "Modelo entrenado y en ejecución."}
|
63 |
+
|
64 |
@spaces.gpu
|
65 |
def run_training():
|
66 |
while True:
|
|
|
73 |
print(f"Error durante el entrenamiento: {e}. Reiniciando el proceso de entrenamiento...")
|
74 |
time.sleep(10)
|
75 |
|
76 |
+
if __name__ == "__main__":
|
77 |
+
import threading
|
78 |
+
threading.Thread(target=run_training).start()
|
79 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|