password
Browse files
app.py
CHANGED
|
@@ -2,12 +2,20 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
ELSA_API_TOKEN = os.getenv("ELSA_API_TOKEN")
|
| 6 |
|
| 7 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
"""
|
| 9 |
Call the ELSA 'score_audio_plus' endpoint with the provided audio file.
|
| 10 |
"""
|
|
|
|
| 11 |
url = "https://api.elsanow.io/api/v1/score_audio_plus"
|
| 12 |
headers = {
|
| 13 |
"Authorization": f"ELSA {ELSA_API_TOKEN}"
|
|
@@ -33,6 +41,8 @@ def score_audio_plus(audio, api_plan, return_json):
|
|
| 33 |
return f"Error: {response.status_code} - {response.text}"
|
| 34 |
|
| 35 |
with gr.Blocks() as blocks:
|
|
|
|
|
|
|
| 36 |
with gr.Row():
|
| 37 |
input_audio = gr.Audio(
|
| 38 |
sources=["microphone"],
|
|
@@ -50,7 +60,7 @@ with gr.Blocks() as blocks:
|
|
| 50 |
|
| 51 |
submit_button.click(
|
| 52 |
fn=score_audio_plus,
|
| 53 |
-
inputs=[input_audio, api_plan, return_json],
|
| 54 |
outputs=output_text
|
| 55 |
)
|
| 56 |
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
PASSWORD = os.getenv("PASSWORD")
|
| 6 |
ELSA_API_TOKEN = os.getenv("ELSA_API_TOKEN")
|
| 7 |
|
| 8 |
+
def verify_password(password):
|
| 9 |
+
if password == PASSWORD:
|
| 10 |
+
return True
|
| 11 |
+
else:
|
| 12 |
+
raise gr.Error("密碼錯誤")
|
| 13 |
+
|
| 14 |
+
def score_audio_plus(password, audio, api_plan, return_json):
|
| 15 |
"""
|
| 16 |
Call the ELSA 'score_audio_plus' endpoint with the provided audio file.
|
| 17 |
"""
|
| 18 |
+
verify_password(password)
|
| 19 |
url = "https://api.elsanow.io/api/v1/score_audio_plus"
|
| 20 |
headers = {
|
| 21 |
"Authorization": f"ELSA {ELSA_API_TOKEN}"
|
|
|
|
| 41 |
return f"Error: {response.status_code} - {response.text}"
|
| 42 |
|
| 43 |
with gr.Blocks() as blocks:
|
| 44 |
+
with gr.Row():
|
| 45 |
+
password = gr.Textbox(label="Password", type="password")
|
| 46 |
with gr.Row():
|
| 47 |
input_audio = gr.Audio(
|
| 48 |
sources=["microphone"],
|
|
|
|
| 60 |
|
| 61 |
submit_button.click(
|
| 62 |
fn=score_audio_plus,
|
| 63 |
+
inputs=[password, input_audio, api_plan, return_json],
|
| 64 |
outputs=output_text
|
| 65 |
)
|
| 66 |
|