ngxson HF staff commited on
Commit
a605ca0
·
1 Parent(s): 4a52fb2

dynamic config

Browse files
Files changed (3) hide show
  1. app.py +3 -1
  2. front/src/config.ts +14 -2
  3. front/src/utils/prompts.ts +2 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import gradio as gr
4
  import os
5
  import random
6
  import torch
 
7
 
8
  print(os.system("""
9
  cd front;
@@ -15,6 +16,7 @@ cd ..;
15
  CHAR_LIMIT = 5000 # test
16
 
17
  SPACE_ID = os.environ.get('SPACE_ID')
 
18
 
19
  CUDA_AVAILABLE = torch.cuda.is_available()
20
  models = {gpu: KModel().to('cuda' if gpu else 'cpu').eval() for gpu in [False] + ([True] if CUDA_AVAILABLE else [])}
@@ -162,7 +164,7 @@ head = f'''
162
  if (!localStorage.getItem('debug') && !window.location.href.match(/debug=1/)) {{
163
  console.log('Attaching frontend app');
164
  const frontendApp = document.createElement('iframe');
165
- frontendApp.src = '/gradio_api/file=./front/dist/index.html?SPACE_ID={SPACE_ID}';
166
  frontendApp.style = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; border: none; z-index: 999999;';
167
  document.body.appendChild(frontendApp);
168
  }}
 
4
  import os
5
  import random
6
  import torch
7
+ from urllib.parse import quote
8
 
9
  print(os.system("""
10
  cd front;
 
16
  CHAR_LIMIT = 5000 # test
17
 
18
  SPACE_ID = os.environ.get('SPACE_ID')
19
+ LLM_ENDPOINT = os.environ.get('LLM_ENDPOINT', 'null')
20
 
21
  CUDA_AVAILABLE = torch.cuda.is_available()
22
  models = {gpu: KModel().to('cuda' if gpu else 'cpu').eval() for gpu in [False] + ([True] if CUDA_AVAILABLE else [])}
 
164
  if (!localStorage.getItem('debug') && !window.location.href.match(/debug=1/)) {{
165
  console.log('Attaching frontend app');
166
  const frontendApp = document.createElement('iframe');
167
+ frontendApp.src = '/gradio_api/file=./front/dist/index.html?SPACE_ID={quote(SPACE_ID)}&LLM_ENDPOINT={quote(LLM_ENDPOINT)}';
168
  frontendApp.style = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; border: none; z-index: 999999;';
169
  document.body.appendChild(frontendApp);
170
  }}
front/src/config.ts CHANGED
@@ -1,5 +1,17 @@
 
 
 
 
 
 
 
 
1
  export const CONFIG = {
2
  llmEndpoint:
3
- 'https://gnb1thady6h3noiz.us-east-1.aws.endpoints.huggingface.cloud/v1/chat/completions',
4
- ttsSpaceId: 'ngxson/kokoro-podcast-generator',
 
 
5
  };
 
 
 
1
+ function getUrlParam(paramName: string): string | null {
2
+ const urlParams = new URLSearchParams(window.location.search);
3
+ return urlParams.get(paramName);
4
+ }
5
+
6
+ const SPACE_ID = getUrlParam('SPACE_ID');
7
+ const LLM_ENDPOINT = getUrlParam('LLM_ENDPOINT');
8
+
9
  export const CONFIG = {
10
  llmEndpoint:
11
+ LLM_ENDPOINT && LLM_ENDPOINT.length > 5
12
+ ? LLM_ENDPOINT
13
+ : 'https://gnb1thady6h3noiz.us-east-1.aws.endpoints.huggingface.cloud/v1/chat/completions',
14
+ ttsSpaceId: SPACE_ID || 'ngxson/kokoro-podcast-generator',
15
  };
16
+
17
+ console.log({ CONFIG });
front/src/utils/prompts.ts CHANGED
@@ -16,7 +16,6 @@ Some rules:
16
  - Only use base ASCII, do NOT use ALL CAPS, strings are wrapped inside "..."
17
  - First turns should be the introduction for the theme and speakers.
18
  - The script will be passed to TTS engine, make sure to write plain pronunciation, for example the www. must pronounced like "www dot"
19
- - Sometimes, try inserting small words like "Yeah?", "Oh!" and set nextGapMilisecs to high negative number to simulate interruptions.
20
 
21
  There is an example (it is truncated):
22
 
@@ -29,11 +28,11 @@ speakerNames:
29
  turns:
30
  - index: 0
31
  speakerName: Alice
32
- text: It wouldn't be better to follow on technology with Magnus Nystedt than to actually cross over using technology to Wellington International School and [Whiz Radio](+1). And who better to kick off the Whiz Radio segment than the person who motivates the students over at Whiz, Wellington International School, than Miss Davy Peel. [Welcome](+1)... [Tell me](-1), give me, give me the scoop here, because I, I came and talked to you a little while ago and said, what do you guys think about doing some kind of a TEDx thing? And then I just sort of backed off.
33
  nextGapMilisecs: 100
34
  - index: 1
35
  speakerName: Davy Peel
36
- text: [Absolutely!](+1) An amazing opportunity to get the kids a bit of kind of creative freedom and, and a forum.
37
  nextGapMilisecs: 1000
38
  \`\`\`
39
  [END OF EXAMPLE]
 
16
  - Only use base ASCII, do NOT use ALL CAPS, strings are wrapped inside "..."
17
  - First turns should be the introduction for the theme and speakers.
18
  - The script will be passed to TTS engine, make sure to write plain pronunciation, for example the www. must pronounced like "www dot"
 
19
 
20
  There is an example (it is truncated):
21
 
 
28
  turns:
29
  - index: 0
30
  speakerName: Alice
31
+ text: It wouldn't be better to follow on technology with Magnus Nystedt than to actually cross over using technology to [Wellington](+1) International School and [Whiz Radio](+1). And who better to kick off the Whiz Radio segment than the person who motivates the students over at Whiz, Wellington International School, than Miss Davy Peel. [Welcome](+2) ... Tell me, give me, give me the scoop here, because I, I came and talked to you a little while ago and said, what do you guys think about doing some kind of a [TEDx](+1) thing? And then I just sort of backed off.
32
  nextGapMilisecs: 100
33
  - index: 1
34
  speakerName: Davy Peel
35
+ text: [Absolutely](+1)... An amazing opportunity to get the kids a bit of kind of creative freedom and, and a forum.
36
  nextGapMilisecs: 1000
37
  \`\`\`
38
  [END OF EXAMPLE]