File size: 1,837 Bytes
b36e1d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import matplotlib.pyplot as plt
from LLM_openai import client, expense_classifier
import datetime
import base64
from io import BytesIO
import re
import json
import matplotlib.dates as mdates

def create_plot(x, y):
    fig, ax = plt.subplots()
    ax.plot(x, y, marker='o')
    for i in range(len(x)):
        ax.text(x[i], y[i], f'{y[i]:.2f}', fontsize=10, ha='left', va='bottom')
    ax.set_xlabel('Money')
    ax.set_ylabel('Expenses')
    ax.set_title('Daily expenses')
    ax.set_xticks(x[::5])  # Show every 5th day
    ax.set_xticklabels(x[::5], rotation=45, ha='right') 
    plt.xticks(rotation=30)
    return fig


def create_barplot(x, y, xlabel,ylabel, title):
    fig, ax = plt.subplots()
    ax.bar(x, y)
    for i in range(len(x)):
        ax.text(x[i], y[i], f'{y[i]:.2f}', fontsize=10, ha='left', va='bottom')
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.set_title(title)
    plt.xticks(rotation=30)
    return fig


####
##OCR functions



def pil_to_base64(pil_img):
    img_buffer = BytesIO()
    pil_img.save(img_buffer, format='JPEG')
    byte_data = img_buffer.getvalue()
    base64_str = base64.b64encode(byte_data).decode("utf-8")
    return base64_str

def js_to_prefere_the_back_camera_of_mobilephones():
    custom_html = """
    <script>
    const originalGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
    
    navigator.mediaDevices.getUserMedia = (constraints) => {
      if (!constraints.video.facingMode) {
        constraints.video.facingMode = {ideal: "environment"};
      }
      return originalGetUserMedia(constraints);
    };
    </script>
    """
    return custom_html

def result_cleaner(text):
    pattern = r'\{[^}]*\}'
    match = re.search(pattern, text)
    match_string=match[0]
    json_dict=json.loads(match_string)


    return json_dict