jbilcke-hf HF staff commited on
Commit
c2b193a
1 Parent(s): 2b10ab2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -52,6 +52,8 @@ import numpy as np
52
  from gradio_client import Client
53
  from huggingface_hub import InferenceClient
54
 
 
 
55
  # This will trigger downloading model
56
  print("Downloading if not downloaded Coqui XTTS V2")
57
 
@@ -612,7 +614,11 @@ latent_map["Pirate"] = get_latents("voices/pirate_by_coqui.wav")
612
  latent_map["Thera"] = get_latents("voices/thera-1.wav")
613
 
614
  # Define the main function for the API endpoint that takes the input text and chatbot role
615
- def generate_story_and_speech(input_text, chatbot_role):
 
 
 
 
616
  # Initialize a list of lists for history with the user input as the first entry
617
  history = [[input_text, None]]
618
  story_sentences = get_sentence(history, chatbot_role) # get_sentence function generates text
@@ -645,7 +651,7 @@ def generate_story_and_speech(input_text, chatbot_role):
645
  # Create a Gradio Interface using only the `generate_story_and_speech()` function and the 'json' output type
646
  demo = gr.Interface(
647
  fn=generate_story_and_speech,
648
- inputs=[gr.Textbox(placeholder="Enter your text here"), gr.Dropdown(choices=ROLES, label="Select Chatbot Role")],
649
  outputs="json"
650
  )
651
 
 
52
  from gradio_client import Client
53
  from huggingface_hub import InferenceClient
54
 
55
+ SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
56
+
57
  # This will trigger downloading model
58
  print("Downloading if not downloaded Coqui XTTS V2")
59
 
 
614
  latent_map["Thera"] = get_latents("voices/thera-1.wav")
615
 
616
  # Define the main function for the API endpoint that takes the input text and chatbot role
617
+ def generate_story_and_speech(secret_token, input_text, chatbot_role):
618
+ if secret_token != SECRET_TOKEN:
619
+ raise gr.Error(
620
+ f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
621
+
622
  # Initialize a list of lists for history with the user input as the first entry
623
  history = [[input_text, None]]
624
  story_sentences = get_sentence(history, chatbot_role) # get_sentence function generates text
 
651
  # Create a Gradio Interface using only the `generate_story_and_speech()` function and the 'json' output type
652
  demo = gr.Interface(
653
  fn=generate_story_and_speech,
654
+ inputs=[gr.Text(label='Secret Token'),gr.Textbox(placeholder="Enter your text here"), gr.Dropdown(choices=ROLES, label="Select Chatbot Role")],
655
  outputs="json"
656
  )
657