Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,72 @@ import pandas as pd
|
|
2 |
import numpy as np
|
3 |
import streamlit as st
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
df = pd.read_csv('heroes_ep.csv')
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import numpy as np
|
3 |
import streamlit as st
|
4 |
|
5 |
+
# import glob
|
6 |
+
# import yaml
|
7 |
+
from pathlib import Path
|
8 |
+
from collections import defaultdict
|
9 |
+
|
10 |
+
#########################################
|
11 |
+
# Helpers Functions
|
12 |
+
|
13 |
+
def filter_by_1col(df, col_name, query, exact_flag=False):
|
14 |
+
|
15 |
+
def check_valid_value(query, string, exact_flag=False):
|
16 |
+
if exact_flag:
|
17 |
+
if query.lower() == string.lower():
|
18 |
+
return True
|
19 |
+
|
20 |
+
elif query.lower() in string.lower():
|
21 |
+
return True
|
22 |
+
|
23 |
+
return False
|
24 |
+
|
25 |
+
ok_flag_list = []
|
26 |
+
assert col_name in df.columns, "col_name must be valid"
|
27 |
+
|
28 |
+
for i, s in enumerate(df[col_name]):
|
29 |
+
|
30 |
+
if isinstance(s, list):
|
31 |
+
for s2 in s:
|
32 |
+
flag = check_valid_value(query, s2, exact_flag=exact_flag)
|
33 |
+
if flag: break
|
34 |
+
else:
|
35 |
+
flag = check_valid_value(query, s, exact_flag=exact_flag)
|
36 |
+
|
37 |
+
|
38 |
+
ok_flag_list.append(flag)
|
39 |
+
|
40 |
+
assert len(ok_flag_list) == len(df)
|
41 |
+
return np.array(ok_flag_list)
|
42 |
+
|
43 |
+
def display_image(url, scale=0.5):
|
44 |
+
from urllib.request import urlopen
|
45 |
+
from PIL import Image
|
46 |
+
|
47 |
+
image = Image.open(urlopen(url))
|
48 |
+
st.image(image.resize(( int(image.width * scale), int(image.height * scale))))
|
49 |
+
|
50 |
+
def display_heroes_from_df(df):
|
51 |
+
display_cols = ['name', 'color', 'star', 'class', 'speed', 'power', 'attack', 'defense', 'health', 'types', 'source', 'family']
|
52 |
+
st.dataframe(df[display_cols])
|
53 |
+
|
54 |
+
for i in range(len(df)):
|
55 |
+
url = df['image'].values[i]
|
56 |
+
display_image(url)
|
57 |
+
st.write(df['skill'].values[i])
|
58 |
+
for sp in df['effects'].values[i]:
|
59 |
+
st.write(sp)
|
60 |
+
|
61 |
+
#########################################
|
62 |
+
|
63 |
+
|
64 |
df = pd.read_csv('heroes_ep.csv')
|
65 |
+
|
66 |
+
idx_all = []
|
67 |
+
idx_all.append(filter_by_1col(df, 'types', 'hit 3'))
|
68 |
+
idx_all.append(filter_by_1col(df, 'effects', 'dispel'))
|
69 |
+
idx_all.append(filter_by_1col(df, 'speed', 'fast', exact_flag=False))
|
70 |
+
|
71 |
+
df2 = df[np.all(idx_all,axis=0)]
|
72 |
+
|
73 |
+
display_heroes_from_df(df2.sort_values("power", ascending=False))
|