Skip to content

Commit 919679f

Browse files
committed
Update flet_chat_gemini
1 parent 299879f commit 919679f

6 files changed

Lines changed: 29 additions & 30 deletions

File tree

examples/official/9.x/flet_chat_gemini/requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/official/9.x/requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/official/9.x/flet_chat_gemini/README.md renamed to examples/official/flet_chat_gemini/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Flet Chat App with Google AI and Dynamsoft Barcode Reader
2-
The project demonstrates how to integrate [Dynamsoft Barcode Reader](https://pypi.org/project/dbr/) and [Gemini APIs](https://ai.google.dev/tutorials/python_quickstart) into a Flet chat app.
2+
The project demonstrates how to integrate [Dynamsoft Barcode Reader](https://pypi.org/project/dynamsoft-barcode-reader-bundle/) and [Gemini APIs](https://ai.google.dev/tutorials/python_quickstart) into a Flet chat app.
33

44
https://github.com/user-attachments/assets/b0f8efd2-ec66-4b02-95c8-e9df437410a7
55

examples/official/9.x/flet_chat_gemini/chatbot.py renamed to examples/official/flet_chat_gemini/chatbot.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
from dbr import *
1+
from dynamsoft_capture_vision_bundle import *
22
import flet as ft
33
import pathlib
44
import google.generativeai as genai
55
import google.ai.generativelanguage as glm
66

7-
license_key = "LICENSE-KEY"
8-
BarcodeReader.init_license(license_key)
9-
reader = BarcodeReader()
7+
license_key = "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ=="
8+
cvr_instance = CaptureVisionRouter()
9+
error_code, error_message = LicenseManager.init_license(license_key)
10+
if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
11+
print("License initialization failed: ErrorCode:",
12+
error_code, ", ErrorString:", error_message)
1013

1114
# https://ai.google.dev/tutorials/python_quickstart
1215
genai.configure(api_key='API_KEY')
@@ -99,26 +102,24 @@ def pick_files_result(e: ft.FilePickerResultEvent):
99102
page.pubsub.send_all(
100103
Message("Me", image_path, message_type="chat_message", is_image=True))
101104

102-
text_results = None
103-
try:
104-
text_results = reader.decode_file(image_path)
105-
106-
# if text_results != None:
107-
# for text_result in text_results:
108-
# print("Barcode Format : ")
109-
# print(text_result.barcode_format_string)
110-
# print("Barcode Text : ")
111-
# print(text_result.barcode_text)
112-
# print("Localization Points : ")
113-
# print(text_result.localization_result.localization_points)
114-
# print("Exception : ")
115-
# print(text_result.exception)
116-
# print("-------------")
117-
except BarcodeReaderError as bre:
118-
print(bre)
119-
120-
if text_results != None:
121-
barcode_text = text_results[0].barcode_text
105+
result = cvr_instance.capture(image_path, EnumPresetTemplate.PT_READ_BARCODES.value)
106+
107+
if result.get_error_code() != EnumErrorCode.EC_OK:
108+
print("Error:", result.get_error_code(),
109+
result.get_error_string())
110+
else:
111+
items = result.get_items()
112+
barcode_text = ""
113+
for item in items:
114+
format_type = item.get_format_string()
115+
text = item.get_text()
116+
print("Barcode Format:", format_type)
117+
print("Barcode Text:", text)
118+
barcode_text += text + " "
119+
120+
if barcode_text == "":
121+
barcode_text = "No barcode found"
122+
122123
page.pubsub.send_all(
123124
Message("DBR", barcode_text, message_type="chat_message"))
124125

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
google-generativeai
2+
dynamsoft-barcode-reader-bundle
3+
flet

0 commit comments

Comments
 (0)