Spaces:
Running
Running
valentynliubchenko
commited on
Commit
·
4a10a29
1
Parent(s):
47e8809
added examples
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- algorithm/product.py +2 -3
- algorithm/receipt.py +0 -8
- algorithm/receipt_calculation.py +6 -6
- app.py +19 -2
- convert_to_webp.py +30 -0
- examples/{farmacy_1.jpg → 5404832557079585491.webp} +2 -2
- examples/ATB_11.jpg +0 -3
- examples/{cafe.png → ATB_11.webp} +2 -2
- examples/{5404832557079585491.jpg → Sportisimo.webp} +2 -2
- examples/{farmacy_2.jpg → cafe.webp} +2 -2
- examples/{Sportisimo.jpg → farmacy_1.webp} +2 -2
- examples/farmacy_2.webp +3 -0
- examples/fatlouis.webp +3 -0
- examples/garm_3.JPG +0 -3
- examples/garm_3.webp +3 -0
- examples/image_2024_09_25T12_13_01_811Z.png +0 -3
- examples/image_2024_09_25T12_13_01_811Z.webp +3 -0
- examples/lidl1.jpg +0 -3
- examples/lidl1.webp +3 -0
- examples/lidl2.jpg +0 -3
- examples/lidl2.webp +3 -0
- examples/photo_2024-09-10_10-06-14.jpg +0 -3
- examples/photo_2024-09-10_10-06-14.webp +3 -0
- examples/photo_2024-09-10_10-06-24.jpg +0 -3
- examples/photo_2024-09-10_10-06-24.webp +3 -0
- examples/photo_2024-09-10_10-06-28.jpg +0 -3
- examples/photo_2024-09-10_10-06-28.webp +3 -0
- examples/photo_2024-09-24_14-50-34.jpg +0 -3
- examples/photo_2024-09-24_14-50-34.webp +3 -0
- examples/tiket.jpg +0 -3
- examples/tiket.webp +3 -0
- examples_canada/photo_2024-10-09_14-21-54.webp +0 -0
- examples_canada/photo_2024-10-09_14-23-03.webp +0 -0
- examples_france/photo_1_2024-10-02_00-08-53.webp +0 -0
- examples_france/photo_2024-10-07_21-46-05.webp +0 -0
- examples_france/photo_2024-10-07_21-46-27.webp +0 -0
- examples_france/photo_2_2024-10-02_00-08-53.webp +0 -0
- examples_france/photo_3_2024-10-02_00-08-53.webp +0 -0
- examples_france/photo_4_2024-10-02_00-08-53.webp +0 -0
- examples_france/photo_5_2024-10-02_00-08-53.webp +0 -0
- examples_france/photo_6_2024-10-02_00-08-53.webp +0 -0
- examples_france/photo_7_2024-10-02_00-08-53.webp +0 -0
- examples_france/photo_8_2024-10-02_00-08-53.webp +0 -0
- examples_us/Photo Sep 29 2024, 15 43 17.webp +0 -0
- examples_us/Photo Sep 29 2024, 15 43 30.webp +0 -0
- examples_us/Photo Sep 29 2024, 15 43 48.webp +0 -0
- examples_us/Photo Sep 29 2024, 15 44 21.webp +0 -0
- examples_us/Photo Sep 29 2024, 15 44 42.webp +0 -0
- examples_us/Photo Sep 29 2024, 15 45 13.webp +0 -0
- examples_us/Photo Sep 29 2024, 15 45 26.webp +0 -0
algorithm/product.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
class Product:
|
| 2 |
-
def __init__(self, name, price
|
| 3 |
self.name = name
|
| 4 |
self.price = price
|
| 5 |
-
self.quantity = quantity
|
| 6 |
|
| 7 |
def __repr__(self):
|
| 8 |
-
return f"Product(name={self.name}, price={self.price}
|
|
|
|
| 1 |
class Product:
|
| 2 |
+
def __init__(self, name, price):
|
| 3 |
self.name = name
|
| 4 |
self.price = price
|
|
|
|
| 5 |
|
| 6 |
def __repr__(self):
|
| 7 |
+
return f"Product(name={self.name}, price={self.price})"
|
algorithm/receipt.py
DELETED
|
@@ -1,8 +0,0 @@
|
|
| 1 |
-
class Receipt:
|
| 2 |
-
def __init__(self, products, tax, total_amount):
|
| 3 |
-
self.products = products
|
| 4 |
-
self.tax = tax
|
| 5 |
-
self.total_amount = total_amount
|
| 6 |
-
|
| 7 |
-
def __repr__(self):
|
| 8 |
-
return f"Receipt(products={self.products}, tax={self.tax}, total_amount={self.total_amount})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithm/receipt_calculation.py
CHANGED
|
@@ -93,21 +93,21 @@ def calculate_tips_and_taxes(items_table, total_amount, tax, tips):
|
|
| 93 |
if items_table[0][0] == "No items":
|
| 94 |
return products, 0
|
| 95 |
|
| 96 |
-
if total_amount == "Not specified" or total_amount is None:
|
| 97 |
total_amount = "0.0"
|
| 98 |
|
| 99 |
-
if tax == "Not specified" or tax is None:
|
| 100 |
tax = "0.0"
|
| 101 |
|
| 102 |
-
if tips == "Not specified" or tips is None:
|
| 103 |
-
|
| 104 |
|
| 105 |
for item in items_table:
|
| 106 |
price = item[5]
|
| 107 |
-
if price == "Not specified":
|
| 108 |
price = "0.0"
|
| 109 |
item_value = float(str(price).replace(",", ".")) if item[5] is not None else 0.0
|
| 110 |
-
products.append(Product(item[0], item_value
|
| 111 |
|
| 112 |
sum_of_product_prices = 0
|
| 113 |
for _product in products:
|
|
|
|
| 93 |
if items_table[0][0] == "No items":
|
| 94 |
return products, 0
|
| 95 |
|
| 96 |
+
if total_amount == "Not specified" or total_amount == "unknown" or total_amount is None:
|
| 97 |
total_amount = "0.0"
|
| 98 |
|
| 99 |
+
if tax == "Not specified" or tax == "unknown" or tax is None:
|
| 100 |
tax = "0.0"
|
| 101 |
|
| 102 |
+
if tips == "Not specified" or tips == "unknown" or tips is None:
|
| 103 |
+
tips = "0.0"
|
| 104 |
|
| 105 |
for item in items_table:
|
| 106 |
price = item[5]
|
| 107 |
+
if price == "Not specified" or price == "unknown":
|
| 108 |
price = "0.0"
|
| 109 |
item_value = float(str(price).replace(",", ".")) if item[5] is not None else 0.0
|
| 110 |
+
products.append(Product(item[0], item_value))
|
| 111 |
|
| 112 |
sum_of_product_prices = 0
|
| 113 |
for _product in products:
|
app.py
CHANGED
|
@@ -14,6 +14,10 @@ from vertex_ai_service import VertexAIService
|
|
| 14 |
model_names = ["gemini-1.5-flash", "gemini-1.5-pro", "gpt-4o-mini", "gpt-4o", "gpt-4-turbo"]
|
| 15 |
prompt_names = ["prompt_v1", "prompt_v2", "prompt_v3"]
|
| 16 |
example_list = [["./examples/" + example] for example in os.listdir("examples")]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
prompt_default = read_prompt_from_file("prompt_v1.txt")
|
| 18 |
system_instruction = read_prompt_from_file("system_instruction.txt")
|
| 19 |
|
|
@@ -258,6 +262,19 @@ with gr.Blocks() as iface:
|
|
| 258 |
)
|
| 259 |
prompt_radio.change(fn=update_prompt_from_radio, inputs=[prompt_radio], outputs=[custom_prompt])
|
| 260 |
gr.Examples(examples=example_list,
|
| 261 |
-
inputs=[image_input, model_radio, prompt_radio, temperature_slider, custom_prompt]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
-
iface.launch(
|
|
|
|
| 14 |
model_names = ["gemini-1.5-flash", "gemini-1.5-pro", "gpt-4o-mini", "gpt-4o", "gpt-4-turbo"]
|
| 15 |
prompt_names = ["prompt_v1", "prompt_v2", "prompt_v3"]
|
| 16 |
example_list = [["./examples/" + example] for example in os.listdir("examples")]
|
| 17 |
+
example_list_us = [["./examples_us/" + example] for example in os.listdir("examples_us")]
|
| 18 |
+
example_list_canada = [["./examples_canada/" + example] for example in os.listdir("examples_canada")]
|
| 19 |
+
example_france = [["./examples_france/" + example] for example in os.listdir("examples_france")]
|
| 20 |
+
|
| 21 |
prompt_default = read_prompt_from_file("prompt_v1.txt")
|
| 22 |
system_instruction = read_prompt_from_file("system_instruction.txt")
|
| 23 |
|
|
|
|
| 262 |
)
|
| 263 |
prompt_radio.change(fn=update_prompt_from_radio, inputs=[prompt_radio], outputs=[custom_prompt])
|
| 264 |
gr.Examples(examples=example_list,
|
| 265 |
+
inputs=[image_input, model_radio, prompt_radio, temperature_slider, custom_prompt],
|
| 266 |
+
label="Examples for general use")
|
| 267 |
+
|
| 268 |
+
gr.Examples(examples=example_list_us,
|
| 269 |
+
inputs=[image_input, model_radio, prompt_radio, temperature_slider, custom_prompt],
|
| 270 |
+
label="Examples for US")
|
| 271 |
+
|
| 272 |
+
gr.Examples(examples=example_list_canada,
|
| 273 |
+
inputs=[image_input, model_radio, prompt_radio, temperature_slider, custom_prompt],
|
| 274 |
+
label="Examples for Canada")
|
| 275 |
+
|
| 276 |
+
gr.Examples(examples=example_france,
|
| 277 |
+
inputs=[image_input, model_radio, prompt_radio, temperature_slider, custom_prompt],
|
| 278 |
+
label="Examples for France")
|
| 279 |
|
| 280 |
+
iface.launch()
|
convert_to_webp.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def convert_to_webp(input_file, output_file=None):
|
| 6 |
+
try:
|
| 7 |
+
img = Image.open(input_file)
|
| 8 |
+
if output_file is None:
|
| 9 |
+
base_name = os.path.splitext(input_file)[0]
|
| 10 |
+
output_file = f"{base_name}.webp"
|
| 11 |
+
|
| 12 |
+
img.save(output_file, "WEBP")
|
| 13 |
+
print(f"saved as {output_file}")
|
| 14 |
+
|
| 15 |
+
except Exception as e:
|
| 16 |
+
print(f"error saving: {e}")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def process_images_in_directory(directory):
|
| 20 |
+
print(directory)
|
| 21 |
+
for filename in os.listdir(directory):
|
| 22 |
+
if filename.lower().endswith(('.jpg', '.png', '.jpeg')):
|
| 23 |
+
input_path = os.path.join(directory, filename)
|
| 24 |
+
convert_to_webp(input_path)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
current_directory = os.getcwd()
|
| 28 |
+
print(f"current_directory: {current_directory}")
|
| 29 |
+
directory = "./examples_france/"
|
| 30 |
+
process_images_in_directory(directory)
|
examples/{farmacy_1.jpg → 5404832557079585491.webp}
RENAMED
|
File without changes
|
examples/ATB_11.jpg
DELETED
Git LFS Details
|
examples/{cafe.png → ATB_11.webp}
RENAMED
|
File without changes
|
examples/{5404832557079585491.jpg → Sportisimo.webp}
RENAMED
|
File without changes
|
examples/{farmacy_2.jpg → cafe.webp}
RENAMED
|
File without changes
|
examples/{Sportisimo.jpg → farmacy_1.webp}
RENAMED
|
File without changes
|
examples/farmacy_2.webp
ADDED
|
Git LFS Details
|
examples/fatlouis.webp
ADDED
|
Git LFS Details
|
examples/garm_3.JPG
DELETED
Git LFS Details
|
examples/garm_3.webp
ADDED
|
Git LFS Details
|
examples/image_2024_09_25T12_13_01_811Z.png
DELETED
Git LFS Details
|
examples/image_2024_09_25T12_13_01_811Z.webp
ADDED
|
Git LFS Details
|
examples/lidl1.jpg
DELETED
Git LFS Details
|
examples/lidl1.webp
ADDED
|
Git LFS Details
|
examples/lidl2.jpg
DELETED
Git LFS Details
|
examples/lidl2.webp
ADDED
|
Git LFS Details
|
examples/photo_2024-09-10_10-06-14.jpg
DELETED
Git LFS Details
|
examples/photo_2024-09-10_10-06-14.webp
ADDED
|
Git LFS Details
|
examples/photo_2024-09-10_10-06-24.jpg
DELETED
Git LFS Details
|
examples/photo_2024-09-10_10-06-24.webp
ADDED
|
Git LFS Details
|
examples/photo_2024-09-10_10-06-28.jpg
DELETED
Git LFS Details
|
examples/photo_2024-09-10_10-06-28.webp
ADDED
|
Git LFS Details
|
examples/photo_2024-09-24_14-50-34.jpg
DELETED
Git LFS Details
|
examples/photo_2024-09-24_14-50-34.webp
ADDED
|
Git LFS Details
|
examples/tiket.jpg
DELETED
Git LFS Details
|
examples/tiket.webp
ADDED
|
Git LFS Details
|
examples_canada/photo_2024-10-09_14-21-54.webp
ADDED
|
examples_canada/photo_2024-10-09_14-23-03.webp
ADDED
|
examples_france/photo_1_2024-10-02_00-08-53.webp
ADDED
|
examples_france/photo_2024-10-07_21-46-05.webp
ADDED
|
examples_france/photo_2024-10-07_21-46-27.webp
ADDED
|
examples_france/photo_2_2024-10-02_00-08-53.webp
ADDED
|
examples_france/photo_3_2024-10-02_00-08-53.webp
ADDED
|
examples_france/photo_4_2024-10-02_00-08-53.webp
ADDED
|
examples_france/photo_5_2024-10-02_00-08-53.webp
ADDED
|
examples_france/photo_6_2024-10-02_00-08-53.webp
ADDED
|
examples_france/photo_7_2024-10-02_00-08-53.webp
ADDED
|
examples_france/photo_8_2024-10-02_00-08-53.webp
ADDED
|
examples_us/Photo Sep 29 2024, 15 43 17.webp
ADDED
|
examples_us/Photo Sep 29 2024, 15 43 30.webp
ADDED
|
examples_us/Photo Sep 29 2024, 15 43 48.webp
ADDED
|
examples_us/Photo Sep 29 2024, 15 44 21.webp
ADDED
|
examples_us/Photo Sep 29 2024, 15 44 42.webp
ADDED
|
examples_us/Photo Sep 29 2024, 15 45 13.webp
ADDED
|
examples_us/Photo Sep 29 2024, 15 45 26.webp
ADDED
|