This is an automated email from the ASF dual-hosted git repository.

vterentev pushed a commit to branch fix-postcommit-python
in repository https://gitbox.apache.org/repos/asf/beam.git

commit 1684d7a3f381662f3ec21bf409e551b8ca7d6a2d
Author: Vitaly Terentyev <[email protected]>
AuthorDate: Sat Jul 26 18:55:53 2025 +0400

    Fix gemini post processor
---
 .../examples/inference/gemini_text_classification.py           | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git 
a/sdks/python/apache_beam/examples/inference/gemini_text_classification.py 
b/sdks/python/apache_beam/examples/inference/gemini_text_classification.py
index e82f407374a..ea7ff235716 100644
--- a/sdks/python/apache_beam/examples/inference/gemini_text_classification.py
+++ b/sdks/python/apache_beam/examples/inference/gemini_text_classification.py
@@ -67,6 +67,16 @@ def parse_known_args(argv):
 
 class PostProcessor(beam.DoFn):
   def process(self, element: PredictionResult) -> Iterable[str]:
+    if hasattr(element, "text"):
+      yield element.text
+      return
+
+    inference = getattr(element, "inference", None)
+
+    if hasattr(inference, "text"):
+      yield inference.text
+      return
+
     yield "Input: " + str(element.example) + " Output: " + str(
         element.inference[1][0].content.parts[0].text)
 

Reply via email to