Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -57,6 +57,11 @@ def LoggaTesto(log_type, data, serializza=True):
|
|
| 57 |
else:
|
| 58 |
formatted_data = data
|
| 59 |
print(f"\n{datetime.now()}: ---------------------------------------------------------------| {log_type} |--------------------------------------------------------------\n{formatted_data}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
#--------------------------------------------------- Generazione TESTO ------------------------------------------------------
|
| 62 |
@app.post("/Genera")
|
|
@@ -71,8 +76,9 @@ def generate_text(request: Request, input_data: InputData):
|
|
| 71 |
max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
|
| 72 |
history = []
|
| 73 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
else:
|
| 77 |
input_data.asincrono = False
|
| 78 |
if input_data.EliminaRisposteNonPertinenti:
|
|
|
|
| 57 |
else:
|
| 58 |
formatted_data = data
|
| 59 |
print(f"\n{datetime.now()}: ---------------------------------------------------------------| {log_type} |--------------------------------------------------------------\n{formatted_data}")
|
| 60 |
+
|
| 61 |
+
def NormalizzaJSON(stringa):
|
| 62 |
+
result_data = {"response": stringa}
|
| 63 |
+
json_result = json.dumps(result_data)
|
| 64 |
+
return json_result
|
| 65 |
|
| 66 |
#--------------------------------------------------- Generazione TESTO ------------------------------------------------------
|
| 67 |
@app.post("/Genera")
|
|
|
|
| 76 |
max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
|
| 77 |
history = []
|
| 78 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 79 |
+
RispostaJSON = NormalizzaJSON(generated_response)
|
| 80 |
+
LoggaTesto("RISPOSTA", RispostaJSON)
|
| 81 |
+
return RispostaJSON
|
| 82 |
else:
|
| 83 |
input_data.asincrono = False
|
| 84 |
if input_data.EliminaRisposteNonPertinenti:
|