Edgar Garcia
Add files via upload
8c19216 unverified
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
import pandas as pd
import matplotlib.pyplot as plt
def create_plot(x, y):
# Set up the figure and axis with a dark background
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#2E3440') # Dark background
ax.set_facecolor('#2E3440') # Match the axis background to the figure
# Plot the line with a vibrant color
ax.plot(x, y, marker='o', color='#88C0D0', linewidth=2, markersize=8, label='Expenses') # Light blue line
# Initialize variables for labeling
last_labeled_y = y.iloc[0] # Start with the first point's y-value
indices_to_label = [0] # Always label the first point
# Loop through the data starting from the second point
for i in range(1, len(y)):
if abs(y.iloc[i] - last_labeled_y) >= 15: # Check if the difference is >= 10
indices_to_label.append(i) # Add the index to the list
last_labeled_y = y.iloc[i] # Update the last labeled y-value
# Always include the last point if it's not already labeled
if len(y) - 1 not in indices_to_label:
indices_to_label.append(len(y) - 1)
# Label the selected points with a contrasting color
for i in indices_to_label:
ax.text(x.iloc[i], y.iloc[i], f'{y.iloc[i]:.1f}', fontsize=10, color='#ECEFF4',
ha='left', va='bottom', bbox=dict(facecolor='#3B4252', alpha=0.8, edgecolor='none'))
# Customize the axis labels and title
ax.set_xlabel('Money', fontsize=12, color='#ECEFF4') # Light gray text
ax.set_ylabel('Expenses', fontsize=12, color='#ECEFF4')
ax.set_title('Daily Expenses', fontsize=14, color='#ECEFF4', pad=20)
# Customize the ticks and grid
ax.tick_params(axis='both', colors='#ECEFF4') # Light gray ticks
ax.set_xticks(x[::5]) # Show every 5th day
ax.set_xticklabels(x[::5], rotation=45, ha='right', color='#ECEFF4')
ax.grid(color='#4C566A', linestyle='--', linewidth=0.5, alpha=0.7) # Subtle grid lines
# Add a legend
#ax.legend(loc='upper left', facecolor='#3B4252', edgecolor='none', fontsize=10, labelcolor='#ECEFF4')
# Adjust layout for better spacing
plt.tight_layout()
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
import matplotlib.pyplot as plt
def create_barplot(x, y, xlabel, ylabel, title):
# Set up the figure and axis with a dark background
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#2E3440') # Dark background
ax.set_facecolor('#2E3440') # Match the axis background to the figure
# Create the bar plot with a vibrant color
bars = ax.bar(x, y, color='#88C0D0', edgecolor='#4C566A', linewidth=1) # Light blue bars with a subtle border
# Add text labels on top of each bar
for i in range(len(x)):
ax.text(
x[i], y[i], f'{y[i]:.2f}',
fontsize=10, color='#ECEFF4', # Light gray text
ha='center', va='bottom', # Center the text horizontally and place it above the bar
bbox=dict(facecolor='#3B4252', alpha=0.8, edgecolor='none') # Semi-transparent background
)
# Customize the axis labels and title
ax.set_xlabel(xlabel, fontsize=12, color='#ECEFF4') # Light gray text
ax.set_ylabel(ylabel, fontsize=12, color='#ECEFF4')
ax.set_title(title, fontsize=14, color='#ECEFF4', pad=20)
# Customize the ticks and grid
ax.tick_params(axis='both', colors='#ECEFF4') # Light gray ticks
plt.xticks(rotation=30, color='#ECEFF4') # Rotate x-axis labels for better readability
ax.grid(color='#4C566A', linestyle='--', linewidth=0.5, alpha=0.7, axis='y') # Subtle horizontal grid lines
# Remove spines (borders) for a cleaner look
for spine in ax.spines.values():
spine.set_visible(False)
# Adjust layout for better spacing
plt.tight_layout()
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