naotokui commited on
Commit
5458994
1 Parent(s): 685c69b

resolution

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -10,7 +10,8 @@ import gradio as gr
10
  openai.api_key = os.environ.get("OPENAI_API_KEY")
11
 
12
  # sample data
13
- markdown_table_sample = """
 
14
  | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
15
  |----|---|---|---|---|---|---|---|---|
16
  | BD | x | | x | | | | x | |
@@ -22,7 +23,8 @@ markdown_table_sample = """
22
  | HT | x | | | x | | | | |
23
  """
24
 
25
- markdown_table_sample2 = """
 
26
  | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15| 16|
27
  |----|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
28
  | BD | x | | x | | | | x | | x | | x | | x | | x | |
@@ -90,7 +92,7 @@ def get_answer(question):
90
  model="gpt-3.5-turbo",
91
  messages=[
92
  {"role": "system", "content": "You are a rhythm generator. "},
93
- {"role": "user", "content": "Please generate a rhythm pattern in a Markdown table. Time resolution is the 8th note. You use the following drums. Kick drum:BD, Snare drum:SD, Closed-hihat:CH, Open-hihat:OH, Low-tom:LT, Mid-tom:MT, High-tom:HT. use 'x' for an accented beat, 'o' for a weak beat."},
94
  {"role": "assistant", "content": markdown_table_sample},
95
  # {"role": "user", "content": "Please generate a rhythm pattern. The resolution is the fourth note. You use the following drums. Kick drum:BD, Snare drum:SD, Closed-hihat:CH, Open-hihat:OH, Low-tom:LT, Mid-tom:MT, High-tom:HT. use 'x' for an accented beat, 'o' for a weak beat. You need to write the time resolution first."},
96
  # {"role": "assistant", "content": markdown_table_sample},
@@ -109,13 +111,12 @@ def generate_rhythm(query, state):
109
  text_output = get_answer(query)
110
 
111
  # Try to use the first row as time resolution
112
- # resolution_text = text_output.split('|')[0]
113
- # try:
114
- # resolution_text = re.findall(r'\d+', resolution_text)[0]
115
- # resolution = int(resolution_text)
116
- # except:
117
- # resolution = 8 # default
118
- resolution = 8 # default
119
 
120
  # Extract rhythm table
121
  table = "|" + "|".join(text_output.split('|')[1:-1]) + "|"
 
10
  openai.api_key = os.environ.get("OPENAI_API_KEY")
11
 
12
  # sample data
13
+ markdown_table_sample = """8th
14
+
15
  | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
16
  |----|---|---|---|---|---|---|---|---|
17
  | BD | x | | x | | | | x | |
 
23
  | HT | x | | | x | | | | |
24
  """
25
 
26
+ markdown_table_sample2 = """16th
27
+
28
  | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15| 16|
29
  |----|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
30
  | BD | x | | x | | | | x | | x | | x | | x | | x | |
 
92
  model="gpt-3.5-turbo",
93
  messages=[
94
  {"role": "system", "content": "You are a rhythm generator. "},
95
+ {"role": "user", "content": "Please generate a rhythm pattern in a Markdown table. Time resolution is the 8th note. You use the following drums. Kick drum:BD, Snare drum:SD, Closed-hihat:CH, Open-hihat:OH, Low-tom:LT, Mid-tom:MT, High-tom:HT. use 'x' for an accented beat, 'o' for a weak beat. You need to write the time resolution first."},
96
  {"role": "assistant", "content": markdown_table_sample},
97
  # {"role": "user", "content": "Please generate a rhythm pattern. The resolution is the fourth note. You use the following drums. Kick drum:BD, Snare drum:SD, Closed-hihat:CH, Open-hihat:OH, Low-tom:LT, Mid-tom:MT, High-tom:HT. use 'x' for an accented beat, 'o' for a weak beat. You need to write the time resolution first."},
98
  # {"role": "assistant", "content": markdown_table_sample},
 
111
  text_output = get_answer(query)
112
 
113
  # Try to use the first row as time resolution
114
+ resolution_text = text_output.split('|')[0]
115
+ try:
116
+ resolution_text = re.findall(r'\d+', resolution_text)[0]
117
+ resolution = int(resolution_text)
118
+ except:
119
+ resolution = 8 # default
 
120
 
121
  # Extract rhythm table
122
  table = "|" + "|".join(text_output.split('|')[1:-1]) + "|"