cotxetj commited on
Commit
65c21fd
1 Parent(s): f152e49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -16,6 +16,20 @@ NUM_THREADS = 2
16
  model = whisper.load_model("small")
17
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def inference(audio):
20
  audio = whisper.load_audio(audio)
21
  print("loading finished")
@@ -137,6 +151,7 @@ def gpt_predict(inputs, request:gr.Request=gr.State([]), top_p = 1, temperature
137
  # decode each line as response data is in bytes
138
  if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
139
  partial_words = partial_words + json.loads(chunk[6:])['choices'][0]["delta"]["content"]
 
140
  if token_counter == 0:
141
  history.append(" " + partial_words)
142
  else:
 
16
  model = whisper.load_model("small")
17
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
18
 
19
+
20
+ def parse_codeblock(text):
21
+ lines = text.split("\n")
22
+ for i, line in enumerate(lines):
23
+ if "```" in line:
24
+ if line != "```":
25
+ lines[i] = f'<pre><code class="{lines[i][3:]}">'
26
+ else:
27
+ lines[i] = '</code></pre>'
28
+ else:
29
+ if i > 0:
30
+ lines[i] = "<br/>" + line.replace("<", "&lt;").replace(">", "&gt;")
31
+ return "".join(lines)
32
+
33
  def inference(audio):
34
  audio = whisper.load_audio(audio)
35
  print("loading finished")
 
151
  # decode each line as response data is in bytes
152
  if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
153
  partial_words = partial_words + json.loads(chunk[6:])['choices'][0]["delta"]["content"]
154
+ print(partial_words)
155
  if token_counter == 0:
156
  history.append(" " + partial_words)
157
  else: