Yhhxhfh commited on
Commit
0dd719b
1 Parent(s): 7e26346

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
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
- run_training()
69
-
70
- import shutil
71
- shutil.rmtree('./results', ignore_errors=True)
 
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)