Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -89,29 +89,35 @@ class BasicAgent:
|
|
89 |
print_coso(f"__call__ file_info: {file_info}")
|
90 |
|
91 |
# Se è presente un file, gestiscilo
|
92 |
-
|
|
|
|
|
93 |
if file_info.endswith((".png", ".jpg", ".jpeg")):
|
94 |
print("coso Image file detected, processing with GPT-4o")
|
95 |
image = get_or_download_image(file_info)
|
96 |
response = self._ask_gpt4o_with_image(image, text)
|
97 |
-
|
98 |
|
99 |
elif file_info.endswith(".wav") or file_name.endswith(".mp3"):
|
100 |
print("coso Audio file detected, processing with Whisper")
|
101 |
audio_bytes = self._load_bytes(file_info)
|
102 |
transcription = self._transcribe_audio(audio_bytes)
|
103 |
-
|
104 |
|
105 |
elif file_info.endswith(".txt"):
|
106 |
print("coso Text file detected")
|
107 |
text_content = self._load_text(file_info)
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
|
|
|
|
|
110 |
|
111 |
-
print_coso("nessun file allegato")
|
112 |
-
# Altrimenti gestisci solo testo
|
113 |
-
return self._ask_gpt4o(text)
|
114 |
|
|
|
115 |
def _ask_gpt4o(self, text: str) -> str:
|
116 |
messages = [{"role": "user", "content": text}]
|
117 |
response = self.client.chat.completions.create(model="gpt-4o-mini", messages=messages)
|
|
|
89 |
print_coso(f"__call__ file_info: {file_info}")
|
90 |
|
91 |
# Se è presente un file, gestiscilo
|
92 |
+
|
93 |
+
risposta = ""
|
94 |
+
|
95 |
if file_info.endswith((".png", ".jpg", ".jpeg")):
|
96 |
print("coso Image file detected, processing with GPT-4o")
|
97 |
image = get_or_download_image(file_info)
|
98 |
response = self._ask_gpt4o_with_image(image, text)
|
99 |
+
risposta = response
|
100 |
|
101 |
elif file_info.endswith(".wav") or file_name.endswith(".mp3"):
|
102 |
print("coso Audio file detected, processing with Whisper")
|
103 |
audio_bytes = self._load_bytes(file_info)
|
104 |
transcription = self._transcribe_audio(audio_bytes)
|
105 |
+
risposta = self._ask_gpt4o(transcription)
|
106 |
|
107 |
elif file_info.endswith(".txt"):
|
108 |
print("coso Text file detected")
|
109 |
text_content = self._load_text(file_info)
|
110 |
+
risposta = self._ask_gpt4o(text_content)
|
111 |
+
else
|
112 |
+
print_coso("nessun file allegato")
|
113 |
+
# Altrimenti gestisci solo testo
|
114 |
+
risposta = self._ask_gpt4o(text)
|
115 |
|
116 |
+
print_coso(f"risposta: {risposta}")
|
117 |
+
return risposta
|
118 |
|
|
|
|
|
|
|
119 |
|
120 |
+
|
121 |
def _ask_gpt4o(self, text: str) -> str:
|
122 |
messages = [{"role": "user", "content": text}]
|
123 |
response = self.client.chat.completions.create(model="gpt-4o-mini", messages=messages)
|