Update src/txagent/txagent.py
Browse files- src/txagent/txagent.py +17 -15
src/txagent/txagent.py
CHANGED
@@ -785,26 +785,28 @@ Generate **one summarized sentence** about "function calls' responses" with nece
|
|
785 |
print("\033[1;32;40mstart\033[0m")
|
786 |
print("len(message)", len(message))
|
787 |
|
788 |
-
# Handle uploaded files
|
789 |
if uploaded_files:
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
|
|
|
|
804 |
|
805 |
if len(message) <= 10:
|
806 |
yield "Hi, I am TxAgent, an assistant for answering biomedical questions. Please provide a valid message with a string longer than 10 characters."
|
807 |
return "Please provide a valid message."
|
|
|
808 |
outputs = []
|
809 |
outputs_str = ''
|
810 |
last_outputs = []
|
|
|
785 |
print("\033[1;32;40mstart\033[0m")
|
786 |
print("len(message)", len(message))
|
787 |
|
|
|
788 |
if uploaded_files:
|
789 |
+
file_content_blocks = []
|
790 |
+
for file in uploaded_files:
|
791 |
+
if file.name.endswith(".pdf"):
|
792 |
+
try:
|
793 |
+
import fitz # PyMuPDF
|
794 |
+
doc = fitz.open(file.name)
|
795 |
+
text = ""
|
796 |
+
for page in doc:
|
797 |
+
text += page.get_text()
|
798 |
+
if text.strip():
|
799 |
+
file_content_blocks.append(f"[FILE CONTENT]\n{text.strip()}\n")
|
800 |
+
except Exception as e:
|
801 |
+
print(f"Error reading PDF: {e}")
|
802 |
+
|
803 |
+
if file_content_blocks:
|
804 |
+
message = "\n".join(file_content_blocks) + "\n[USER PROMPT]\n" + message
|
805 |
|
806 |
if len(message) <= 10:
|
807 |
yield "Hi, I am TxAgent, an assistant for answering biomedical questions. Please provide a valid message with a string longer than 10 characters."
|
808 |
return "Please provide a valid message."
|
809 |
+
|
810 |
outputs = []
|
811 |
outputs_str = ''
|
812 |
last_outputs = []
|