MatteoScript commited on
Commit
2997fee
·
verified ·
1 Parent(s): edfd1c7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -4
main.py CHANGED
@@ -49,8 +49,9 @@ class PostSpazio(BaseModel):
49
  input: str = ''
50
  api_name: str = "/chat"
51
 
52
- def LoggaTesto(log_type, text):
53
- print(f"{datetime.now()}: ----------------------------------| {log_type} |-----------------------------------\n{text}\n\n")
 
54
 
55
  #--------------------------------------------------- Generazione TESTO ------------------------------------------------------
56
  @app.post("/Genera")
@@ -65,12 +66,12 @@ def generate_text(request: Request, input_data: InputData):
65
  max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
66
  history = []
67
  generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
68
- LoggaTesto("RISPOSTA SINCRONA", generated_response)
69
  return {"response": generated_response}
70
  else:
71
  input_data.asincrono = False
72
  result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
73
- LoggaTesto("RISPOSTA ASINCRONA FINALE", result_data)
74
  return {"response": result_data}
75
 
76
  def generate_input_text(input_data):
 
49
  input: str = ''
50
  api_name: str = "/chat"
51
 
52
+ def LoggaTesto(log_type, data):
53
+ formatted_data = json.dumps(data, indent=2)
54
+ print(f"\n{datetime.now()}: ---------------------------------------------------------------| {log_type} |-------------------------------------------------------------------\n{formatted_data}")
55
 
56
  #--------------------------------------------------- Generazione TESTO ------------------------------------------------------
57
  @app.post("/Genera")
 
66
  max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
67
  history = []
68
  generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
69
+ LoggaTesto("RISPOSTA SINCRONA", {"response": generated_response})
70
  return {"response": generated_response}
71
  else:
72
  input_data.asincrono = False
73
  result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
74
+ LoggaTesto("RISPOSTA ASINCRONA FINALE", {"response": result_data})
75
  return {"response": result_data}
76
 
77
  def generate_input_text(input_data):