Skip to content

Commit c941fa4

Browse files
added some examples
1 parent d9e40a7 commit c941fa4

File tree

5 files changed

+306
-0
lines changed

5 files changed

+306
-0
lines changed

part-08/data/employees.xlsx

0 Bytes
Binary file not shown.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import streamlit as st
2+
import yfinance as yf
3+
import plotly.graph_objects as go
4+
from datetime import datetime
5+
6+
st.set_page_config(page_title="Stock Analyzer", layout="wide")
7+
8+
# Title
9+
st.title('Stock Price Analysis')
10+
11+
# Sidebar controls
12+
with st.sidebar:
13+
st.header('Settings')
14+
15+
# Stock ticker input
16+
ticker = st.text_input('Stock Ticker', 'REMEDY.HE')
17+
18+
# Time range selector
19+
timeframe = st.radio(
20+
'Select Timeframe',
21+
options=[
22+
('1 Month', 30),
23+
('3 Months', 90),
24+
('6 Months', 180),
25+
('1 Year', 365),
26+
('2 Years', 730)
27+
],
28+
format_func=lambda x: x[0]
29+
)
30+
31+
# Fetch data
32+
@st.cache_data(ttl=3600) # Cache data for 1 hour
33+
def load_data(ticker_symbol):
34+
stock = yf.Ticker(ticker_symbol)
35+
return stock.history(period="2y")
36+
37+
try:
38+
# Load the data
39+
df = load_data(ticker)
40+
41+
# Filter based on selected timeframe
42+
filtered_df = df.iloc[-timeframe[1]:]
43+
44+
# Create candlestick chart
45+
fig = go.Figure()
46+
47+
# Add candlestick
48+
fig.add_trace(go.Candlestick(
49+
x=filtered_df.index,
50+
open=filtered_df['Open'],
51+
high=filtered_df['High'],
52+
low=filtered_df['Low'],
53+
close=filtered_df['Close'],
54+
name='OHLC'
55+
))
56+
57+
# Add volume bars
58+
fig.add_trace(go.Bar(
59+
x=filtered_df.index,
60+
y=filtered_df['Volume'],
61+
name='Volume',
62+
yaxis='y2',
63+
marker_color='rgba(128,128,128,0.5)'
64+
))
65+
66+
# Update layout
67+
fig.update_layout(
68+
title=f'{ticker} Stock Price',
69+
yaxis_title='Stock Price',
70+
yaxis2=dict(
71+
title='Volume',
72+
overlaying='y',
73+
side='right'
74+
),
75+
xaxis_rangeslider_visible=False,
76+
template='plotly_white',
77+
height=600
78+
)
79+
80+
# Display the chart
81+
st.plotly_chart(fig, use_container_width=True)
82+
83+
# Display additional information
84+
col1, col2, col3 = st.columns(3)
85+
86+
with col1:
87+
st.metric(
88+
"Current Price",
89+
f"${filtered_df['Close'][-1]:.2f}",
90+
f"{((filtered_df['Close'][-1] - filtered_df['Close'][-2]) / filtered_df['Close'][-2] * 100):.2f}%"
91+
)
92+
93+
with col2:
94+
st.metric(
95+
"Highest Price",
96+
f"${filtered_df['High'].max():.2f}"
97+
)
98+
99+
with col3:
100+
st.metric(
101+
"Lowest Price",
102+
f"${filtered_df['Low'].min():.2f}"
103+
)
104+
105+
# Display raw data if desired
106+
if st.checkbox('Show Raw Data'):
107+
st.dataframe(filtered_df)
108+
109+
except Exception as e:
110+
st.error(f"Error loading data for {ticker}. Please check if the ticker symbol is correct.")
111+
st.exception(e)
112+
113+
# Footer
114+
st.markdown("---")
115+
st.markdown("Data provided by Yahoo Finance")

part-10/projects/deep_face.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import cv2
2+
from deepface import DeepFace
3+
import numpy as np
4+
5+
def analyze_webcam():
6+
# Initialize the webcam
7+
cap = cv2.VideoCapture(0)
8+
9+
while True:
10+
# Read frame from webcam
11+
ret, frame = cap.read()
12+
if not ret:
13+
break
14+
15+
try:
16+
# Analyze the frame using DeepFace
17+
analysis = DeepFace.analyze(frame,
18+
actions=['age', 'gender', 'emotion', 'race'],
19+
enforce_detection=False)
20+
21+
# Extract results
22+
age = analysis[0]['age']
23+
gender = analysis[0]['gender']
24+
emotion = analysis[0]['dominant_emotion']
25+
race = analysis[0]['dominant_race']
26+
27+
# Add text to frame
28+
font = cv2.FONT_HERSHEY_SIMPLEX
29+
cv2.putText(frame, f'Age: {age}', (10, 30), font, 1, (0, 255, 0), 2)
30+
cv2.putText(frame, f'Gender: {gender}', (10, 70), font, 1, (0, 255, 0), 2)
31+
cv2.putText(frame, f'Emotion: {emotion}', (10, 110), font, 1, (0, 255, 0), 2)
32+
cv2.putText(frame, f'Race: {race}', (10, 150), font, 1, (0, 255, 0), 2)
33+
34+
except Exception as e:
35+
# If no face is detected or other error occurs, continue to next frame
36+
pass
37+
38+
# Display the frame
39+
cv2.imshow('Webcam Analysis', frame)
40+
41+
# Break loop on 'q' press
42+
if cv2.waitKey(1) & 0xFF == ord('q'):
43+
break
44+
45+
# Release resources
46+
cap.release()
47+
cv2.destroyAllWindows()
48+
49+
if __name__ == "__main__":
50+
analyze_webcam()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import torch
2+
from transformers import AutoTokenizer, AutoModelForCausalLM
3+
4+
model_name = "infly/OpenCoder-1.5B-Instruct"
5+
model = AutoModelForCausalLM.from_pretrained(model_name,
6+
torch_dtype=torch.bfloat16,
7+
device_map="auto",
8+
#device_map=torch.device("cpu"),
9+
trust_remote_code=True)
10+
11+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)

0 commit comments

Comments
 (0)