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
The following commit(s) were added to refs/heads/fix-postcommit-python by this
push:
new 3b1f0eef51d Fix gemini post processor
3b1f0eef51d is described below
commit 3b1f0eef51d0bd939e3534d941484a734ee080ed
Author: Vitaly Terentyev <[email protected]>
AuthorDate: Sun Jul 27 09:29:23 2025 +0400
Fix gemini post processor
---
.../inference/gemini_text_classification.py | 26 ++++++----------------
1 file changed, 7 insertions(+), 19 deletions(-)
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 428f86f0e69..c626b18b38f 100644
--- a/sdks/python/apache_beam/examples/inference/gemini_text_classification.py
+++ b/sdks/python/apache_beam/examples/inference/gemini_text_classification.py
@@ -67,30 +67,18 @@ 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
-
- if hasattr(inference[1], "text"):
- yield inference[1].text
- return
-
- if hasattr(inference[1][0], "text"):
- yield inference[1][0].text
- return
-
- if hasattr(inference[1][0].content, "text"):
- yield inference[1][0].content.text
+ if hasattr(inference[1], "content"):
+ yield inference[1].content.parts[0].text
return
- yield "Input: " + str(element.example) + " Output: " + str(
- element.inference[1][0].content.parts[0].text)
+ if isinstance(inference[1], (tuple, list)) and len(inference) > 1:
+ yield "Input: " + str(element.example) + " Output: " + str(
+ inference[1][0].content.parts[0].text)
+ else:
+ yield "Can't decode inference output"
def run(