Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -57,15 +57,12 @@ 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 |
-
def NormalizzaJSON(stringa):
|
62 |
-
json_result = json.dumps({"response": stringa})
|
63 |
-
return json_result
|
64 |
|
65 |
#--------------------------------------------------- Generazione TESTO ------------------------------------------------------
|
66 |
@app.post("/Genera")
|
67 |
def generate_text(request: Request, input_data: InputData):
|
68 |
if not input_data.asincrono:
|
|
|
69 |
temperature = input_data.temperature
|
70 |
max_new_tokens = input_data.max_new_tokens
|
71 |
top_p = input_data.top_p
|
@@ -85,6 +82,7 @@ def generate_text(request: Request, input_data: InputData):
|
|
85 |
input_data.input = input_data.input + msgEliminaRisposteNonPertinenti
|
86 |
input_data.systemRole = input_data.systemRole + msgEliminaRisposteNonPertinenti
|
87 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
|
|
88 |
LoggaTesto("RISPOSTA ASINCRONA", {"response": result_data})
|
89 |
if input_data.EliminaRisposteNonPertinenti:
|
90 |
result_data = [item for item in result_data if "NOTFOUND" not in item["response"]]
|
@@ -94,6 +92,7 @@ def generate_text(request: Request, input_data: InputData):
|
|
94 |
input_data.systemStyle = 'Rispondi in ITALIANO'
|
95 |
input_data.instruction =''
|
96 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
|
|
97 |
LoggaTesto("RISPOSTA ASINCRONA UNIFICATA", {"response": result_data})
|
98 |
return {"response": result_data}
|
99 |
|
|
|
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")
|
63 |
def generate_text(request: Request, input_data: InputData):
|
64 |
if not input_data.asincrono:
|
65 |
+
LoggaTesto("INPUT", input_data.input, False)
|
66 |
temperature = input_data.temperature
|
67 |
max_new_tokens = input_data.max_new_tokens
|
68 |
top_p = input_data.top_p
|
|
|
82 |
input_data.input = input_data.input + msgEliminaRisposteNonPertinenti
|
83 |
input_data.systemRole = input_data.systemRole + msgEliminaRisposteNonPertinenti
|
84 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
85 |
+
result_data = result_data.replace('"', '')
|
86 |
LoggaTesto("RISPOSTA ASINCRONA", {"response": result_data})
|
87 |
if input_data.EliminaRisposteNonPertinenti:
|
88 |
result_data = [item for item in result_data if "NOTFOUND" not in item["response"]]
|
|
|
92 |
input_data.systemStyle = 'Rispondi in ITALIANO'
|
93 |
input_data.instruction =''
|
94 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
95 |
+
result_data = result_data.replace('"', '')
|
96 |
LoggaTesto("RISPOSTA ASINCRONA UNIFICATA", {"response": result_data})
|
97 |
return {"response": result_data}
|
98 |
|