thelou1s commited on
Commit
9492e32
1 Parent(s): 5152fab

test app.py with db ok

Browse files
Files changed (4) hide show
  1. analysis_db.py +23 -8
  2. app.py +23 -102
  3. draw_db.py +11 -4
  4. requirements.txt +3 -8
analysis_db.py CHANGED
@@ -6,8 +6,19 @@ from draw_db import draw_lists, min_max_list, up_down_list
6
  from util.date_util import format_date
7
 
8
 
 
 
 
 
 
 
 
 
 
 
9
  def read_section(db_name, tb_name='tb_section', section_id=''):
10
- debug_print('read_db, db_name = ', db_name, ', tb_name = ', tb_name, ', section_id = ', section_id)
 
11
  conn = sqlite3.connect(db_name)
12
 
13
  if not tb_name:
@@ -25,11 +36,12 @@ def read_section(db_name, tb_name='tb_section', section_id=''):
25
  section_end_date = section_row[2]
26
  print('section_id = ', section_id, ', section_date = ', format_date(section_date), ', section_end_date = ',
27
  format_date(section_end_date))
28
- read_sample(conn, section_id, tb_name)
29
  else:
30
- read_sample(conn, section_id, tb_name)
31
 
32
  conn.close()
 
33
 
34
 
35
  def read_sample(conn, section_id, tb_name):
@@ -72,11 +84,14 @@ def read_sample(conn, section_id, tb_name):
72
  screen_list.append(screen)
73
 
74
  title_str = str(section_id) + ', ' + str(format_date(section_date)) + ', ' + str(format_date(section_end_date))
75
- light_min = min(light_list)
76
- light_max = max(light_list)
77
- screen_list = min_max_list(screen_list, light_min, light_max)
78
- screen_list = up_down_list(screen_list)
79
- draw_lists(title_str, date_list, max=max_list, min=min_list, acc=acc_list, screen=screen_list, light=light_list)
 
 
 
80
 
81
 
82
  if __name__ == '__main__':
 
6
  from util.date_util import format_date
7
 
8
 
9
+ def get_filename(file_obj):
10
+ return file_obj.name
11
+
12
+
13
+ def read_db(db_file):
14
+ db_name = get_filename(db_file)
15
+ debug_print('read_db, db_name = ', db_name)
16
+ return read_section(db_name, 'tb_section', '')
17
+
18
+
19
  def read_section(db_name, tb_name='tb_section', section_id=''):
20
+ res_fig = None
21
+ debug_print('read_section, db_name = ', db_name, ', tb_name = ', tb_name, ', section_id = ', section_id)
22
  conn = sqlite3.connect(db_name)
23
 
24
  if not tb_name:
 
36
  section_end_date = section_row[2]
37
  print('section_id = ', section_id, ', section_date = ', format_date(section_date), ', section_end_date = ',
38
  format_date(section_end_date))
39
+ res_fig = read_sample(conn, section_id, tb_name)
40
  else:
41
+ res_fig = read_sample(conn, section_id, tb_name)
42
 
43
  conn.close()
44
+ return res_fig
45
 
46
 
47
  def read_sample(conn, section_id, tb_name):
 
84
  screen_list.append(screen)
85
 
86
  title_str = str(section_id) + ', ' + str(format_date(section_date)) + ', ' + str(format_date(section_end_date))
87
+
88
+ if len(light_list) > 0:
89
+ light_min = min(light_list)
90
+ light_max = max(light_list)
91
+ screen_list = min_max_list(screen_list, light_min, light_max)
92
+ screen_list = up_down_list(screen_list)
93
+ return draw_lists(title_str, date_list, max=max_list, min=min_list, acc=acc_list, screen=screen_list,
94
+ light=light_list)
95
 
96
 
97
  if __name__ == '__main__':
app.py CHANGED
@@ -1,103 +1,24 @@
1
  import gradio as gr
2
- from test import predict_uri
3
- import sys
4
- import warnings
5
- from fastapi import FastAPI
6
-
7
- # ignore UserWarning
8
- warnings.simplefilter("ignore", UserWarning)
9
-
10
- # examples = [
11
- # ['res/miaow_16k.wav'],
12
- # ['res/snore/pro_snore 6bee45643b45af9b_a7a3bbe6ba79af5b25b19ad10a8d9421d0d5679b.wav'],
13
- # ['res/snore/Snoring vs Sleep Apnea - What the difference sounds like.mp4']
14
- # ]
15
- title = "yamnet test"
16
- description = "An audio event classifier trained on the AudioSet dataset to predict audio events from the AudioSet ontology."
17
-
18
- # # https://github.com/gradio-app/gradio/issues/2362
19
- # class Logger:
20
- # def __init__(self, filename):
21
- # self.terminal = sys.stdout
22
- # self.log = open(filename, "w")
23
- #
24
- # def write(self, message):
25
- # self.terminal.write(message)
26
- # self.log.write(message)
27
- #
28
- # def flush(self):
29
- # self.terminal.flush()
30
- # self.log.flush()
31
- #
32
- # def isatty(self):
33
- # return False
34
- #
35
- #
36
- # sys.stdout = Logger("output.log")
37
- #
38
- #
39
- # def test(x):
40
- # print("This is a test")
41
- # print(f"Your function is running with input {x}...")
42
- # return x
43
- #
44
- #
45
- # def read_logs():
46
- # sys.stdout.flush()
47
- # with open("output.log", "r") as f:
48
- # return f.read()
49
- #
50
- #
51
- # with gr.Interface(predict_uri, inputs=gr.inputs.Audio(type="filepath"), outputs=["text", 'plot']) as demo:
52
- # examples = examples,
53
- # title = title,
54
- # description = description,
55
- # allow_flagging = 'never'
56
- #
57
- # logs = gr.Textbox()
58
- # demo.load(read_logs, None, logs, every=1)
59
- #
60
- # demo.launch(enable_queue=True, show_error=True)
61
-
62
-
63
- # with gr.Blocks() as demo:
64
- # with gr.Row():
65
- # inputs = gr.inputs.Audio(type="filepath")
66
- # outputs = ["text", 'plot']
67
- # btn = gr.Button("Run")
68
- # btn.click(predict_uri, inputs, outputs)
69
- #
70
- # logs = gr.Textbox()
71
- # demo.load(read_logs, None, logs, every=1)
72
- #
73
- # demo.queue().launch()
74
-
75
-
76
- demo = gr.Interface(
77
- predict_uri,
78
- inputs=[
79
- gr.inputs.Audio(type="filepath"),
80
- gr.inputs.Audio(source="microphone", type="filepath"),
81
- gr.Slider(minimum=7, maximum=21, step=1)
82
- ],
83
- outputs=['image', 'image', 'image', 'text', 'text', 'text', 'text'],
84
- # examples=examples,
85
- title=title,
86
- description=description,
87
- allow_flagging='never'
88
- )
89
- demo.launch(enable_queue=True, show_error=True, share=False)
90
-
91
- # # FastAPI
92
- # CUSTOM_PATH = "/gradio"
93
- #
94
- # app = FastAPI()
95
- #
96
- #
97
- # @app.get("/")
98
- # def read_main():
99
- # return {"message": "This is your main app"}
100
- #
101
- #
102
- # io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
103
- # app = gr.mount_gradio_app(app, io, path=CUSTOM_PATH)
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ from analysis_db import read_db
6
+
7
+
8
+ def plot_pens(alpha):
9
+ df_pens = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv')
10
+ fig = plt.figure()
11
+ plt.scatter(x=df_pens['bill_length_mm'], y=df_pens['bill_depth_mm'])
12
+ return fig
13
+
14
+
15
+ iface = gr.Interface(
16
+ fn=read_db,
17
+ layout='vertical',
18
+ inputs=['file'],
19
+ outputs=['plot'],
20
+ title="Sleep Data test",
21
+ description="Let's talk pens.",
22
+ article="Talk more about Penguins here, shall we?",
23
+ theme='peach'
24
+ ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
draw_db.py CHANGED
@@ -2,6 +2,7 @@ import math
2
 
3
  import matplotlib.pyplot as plt
4
 
 
5
  from util.debug import debug_print
6
 
7
 
@@ -24,8 +25,7 @@ def min_max_list(src_list, tar_min, tar_max):
24
 
25
 
26
  def draw_lists(title='', date_list=None, **kv_list):
27
- debug_print('draw_three, date_list = ', str(date_list))
28
- # debug_print('draw_three, light_list = ', str(light_list))
29
 
30
  idx_list = 0
31
  idx_axs = 0
@@ -38,8 +38,15 @@ def draw_lists(title='', date_list=None, **kv_list):
38
  idx_list = idx_list + 1
39
  idx_axs = int(idx_list / 3)
40
 
41
- if debug.DEBUG:
42
- plt.show()
 
 
 
 
 
43
  else:
44
  file_uri = '.doc/' + title + '.png'
45
  fig.savefig(file_uri)
 
 
 
2
 
3
  import matplotlib.pyplot as plt
4
 
5
+ from util.debug import DEBUG
6
  from util.debug import debug_print
7
 
8
 
 
25
 
26
 
27
  def draw_lists(title='', date_list=None, **kv_list):
28
+ debug_print('draw_lists, date_list = ', str(date_list))
 
29
 
30
  idx_list = 0
31
  idx_axs = 0
 
38
  idx_list = idx_list + 1
39
  idx_axs = int(idx_list / 3)
40
 
41
+ plt.gcf().autofmt_xdate()
42
+ # plt.title(title)
43
+
44
+ if DEBUG:
45
+ # plt.show()
46
+ file_uri = '.doc/' + title + '.png'
47
+ fig.savefig(file_uri)
48
  else:
49
  file_uri = '.doc/' + title + '.png'
50
  fig.savefig(file_uri)
51
+
52
+ return fig
requirements.txt CHANGED
@@ -1,11 +1,6 @@
1
- Pillow
2
- librosa
3
- soundfile
4
- matplotlib==3.7.2
5
  gradio
6
- tensorflow
7
- tensorflow_hub
8
  numpy
9
  scipy
10
- pydub
11
- seaborn
 
 
 
 
 
1
  gradio
2
+ matplotlib==3.7.2
 
3
  numpy
4
  scipy
5
+ pandas
6
+ sqlite3