Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
import warnings
|
2 |
-
from transformers.utils import logging as transformers_logging
|
3 |
import torch
|
4 |
import yfinance as yf
|
5 |
import matplotlib.pyplot as plt
|
@@ -9,23 +7,22 @@ import gradio as gr
|
|
9 |
import logging
|
10 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
11 |
|
12 |
-
# Suppress specific FutureWarnings from transformers library
|
13 |
-
warnings.filterwarnings("ignore", category=FutureWarning, message=".*vocab_size.*")
|
14 |
-
|
15 |
-
# Optionally, configure the transformers logging to avoid clutter
|
16 |
-
transformers_logging.set_verbosity_error()
|
17 |
-
|
18 |
# Configure logging to write to a file
|
19 |
logging.basicConfig(filename='debug.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
20 |
|
21 |
-
# Check
|
22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
-
|
24 |
-
|
25 |
|
26 |
# Load the ChartGemma model and processor
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# Function to fetch stock data with different intervals
|
31 |
def fetch_stock_data(ticker='TSLA', start='2023-01-01', end='2024-01-01', interval='1d'):
|
@@ -45,18 +42,11 @@ def create_stock_chart(data, ticker, filename='chart.png', timeframe='1d'):
|
|
45 |
logging.debug(f"Creating chart for {ticker} with timeframe {timeframe} and saving to {filename}")
|
46 |
title = f"{ticker.upper()} Price Data (Timeframe: {timeframe})"
|
47 |
|
48 |
-
# Set the title font size using rcParams
|
49 |
plt.rcParams["axes.titlesize"] = 10
|
50 |
-
|
51 |
-
# Define the style for the chart
|
52 |
my_style = mpf.make_mpf_style(base_mpf_style='charles')
|
53 |
-
|
54 |
fig, axlist = mpf.plot(data, type='candle', style=my_style, volume=True, returnfig=True)
|
55 |
-
|
56 |
-
|
57 |
-
fig.suptitle(title, y=0.98) # Adjust the y parameter to move the title down
|
58 |
-
|
59 |
-
fig.savefig(filename, dpi=300) # Increased DPI
|
60 |
plt.close(fig)
|
61 |
|
62 |
# Resize image to 3 times its original size
|
|
|
|
|
|
|
1 |
import torch
|
2 |
import yfinance as yf
|
3 |
import matplotlib.pyplot as plt
|
|
|
7 |
import logging
|
8 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# Configure logging to write to a file
|
11 |
logging.basicConfig(filename='debug.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
12 |
|
13 |
+
# Check GPU availability and initialize device
|
14 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
+
print("CUDA Available:", torch.cuda.is_available())
|
16 |
+
print("Using device:", device)
|
17 |
|
18 |
# Load the ChartGemma model and processor
|
19 |
+
try:
|
20 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained("ahmed-masry/chartgemma", torch_dtype=torch.float16).to(device)
|
21 |
+
processor = AutoProcessor.from_pretrained("ahmed-masry/chartgemma")
|
22 |
+
print("Model and processor loaded successfully.")
|
23 |
+
except Exception as e:
|
24 |
+
print("Error loading model or processor:", e)
|
25 |
+
logging.error(f"Error loading model or processor: {e}")
|
26 |
|
27 |
# Function to fetch stock data with different intervals
|
28 |
def fetch_stock_data(ticker='TSLA', start='2023-01-01', end='2024-01-01', interval='1d'):
|
|
|
42 |
logging.debug(f"Creating chart for {ticker} with timeframe {timeframe} and saving to {filename}")
|
43 |
title = f"{ticker.upper()} Price Data (Timeframe: {timeframe})"
|
44 |
|
|
|
45 |
plt.rcParams["axes.titlesize"] = 10
|
|
|
|
|
46 |
my_style = mpf.make_mpf_style(base_mpf_style='charles')
|
|
|
47 |
fig, axlist = mpf.plot(data, type='candle', style=my_style, volume=True, returnfig=True)
|
48 |
+
fig.suptitle(title, y=0.98)
|
49 |
+
fig.savefig(filename, dpi=300)
|
|
|
|
|
|
|
50 |
plt.close(fig)
|
51 |
|
52 |
# Resize image to 3 times its original size
|