Spaces:
Runtime error
Runtime error
Commit
·
89d4656
1
Parent(s):
dd657ca
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
import spacy
|
@@ -7,10 +9,9 @@ import pandas as pd
|
|
7 |
import os
|
8 |
import requests
|
9 |
from textwrap import wrap
|
|
|
10 |
import gspread
|
11 |
|
12 |
-
os.system('python -m spacy download en_core_web_sm')
|
13 |
-
|
14 |
nlp = spacy.load("en_core_web_sm")
|
15 |
nlp.add_pipe('sentencizer')
|
16 |
|
@@ -39,11 +40,7 @@ with open('credentials.json', 'w') as f:
|
|
39 |
json.dump(data, f)
|
40 |
|
41 |
|
42 |
-
|
43 |
-
sh = gc.open('Annotated CC Audio')
|
44 |
-
worksheet = sh.sheet1
|
45 |
-
df = pd.DataFrame(worksheet.get_all_records())
|
46 |
-
sample_df = df[df['caption']==''].sample(1)
|
47 |
|
48 |
title = '🎵 Annotate audio'
|
49 |
description = '''Choose a sentence that describes audio the best if there's no such sentence please choose `No audio description`'''
|
@@ -51,22 +48,34 @@ description = '''Choose a sentence that describes audio the best if there's no s
|
|
51 |
audio_dir = 'AUDIO'
|
52 |
os.makedirs(audio_dir, exist_ok=True)
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
def audio_demo(cap, audio,
|
|
|
61 |
|
62 |
-
df
|
|
|
63 |
worksheet.update([df.columns.values.tolist()] + df.values.tolist())
|
64 |
return 'success!'
|
65 |
|
|
|
66 |
|
67 |
iface = gr.Interface(
|
68 |
audio_demo,
|
69 |
-
inputs=[gr.
|
70 |
outputs=[gr.Textbox(label="output")],
|
71 |
allow_flagging="never",
|
72 |
title=title,
|
|
|
1 |
+
%env CREDENTIALS={"type": "service_account","project_id": "plenary-shade-368614","private_key_id": "ff8317f1c399300a6db5ad5a1357720d7e9a6d6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ML4X\nVtO+GtEFu4qUYTGYC7tdD6qOQrlhW5J1ZfVBALxKscyk1hj6zO2AIeAKP/RfS6As\nIrRDzHF67wKBgAo8tEn5vAi8D97Jphy9yBUOE1awnLDBsadOWPP8sWzKpXDB5WUJ\n1QcnDL3LaCyqUYr7welnwIL5TLbDEg/mIiuIZ2f9QbVOT9+YAhZOForovPHmZ5CN\ntPqW6YADoEyUQBQLJIpokV5x6+zksMT48bsxvYo8KwDMvUjetHayOQrhAoGAZInq\nZZaJbFYW24+dDYfZzXzfUhA6H6e3pH8iAt7yafxuJ/MCRG0tOPYENeDB4tbwT9KR\nVA2YuNcsVruBIllE2vCOP6N62AHOnjZ6Cyi+IyZYR/VzZuQWwjgyEF/uoXkN1dr8\nEZAZFexpoxYqzEQLJTqP/0TrkvjsnV7nqUUSJDsCgYA3T1OZU4/NLxp61jQRRLEd\nF2TgOwZ1m6j6Up5J1YMthDQpywREPPonCnjC7FWTw7a1VimHochdzeCjT/PSPOvC\nZdX/6Gej2yMQ3QPTtoBS+BdyfUeJCu1Z07BlwJO3wC7qH/N4YfU8wQqFdO2WZg6+\n4MDWth7MP5LI+udNYczhUA==\n-----END PRIVATE KEY-----\n", "client_email": "[email protected]","client_id": "106523013017816734094","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://oauth2.googleapis.com/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/annotation-app%40plenary-shade-368614.iam.gserviceaccount.com"}
|
2 |
+
|
3 |
import gradio as gr
|
4 |
import json
|
5 |
import spacy
|
|
|
9 |
import os
|
10 |
import requests
|
11 |
from textwrap import wrap
|
12 |
+
import uuid
|
13 |
import gspread
|
14 |
|
|
|
|
|
15 |
nlp = spacy.load("en_core_web_sm")
|
16 |
nlp.add_pipe('sentencizer')
|
17 |
|
|
|
40 |
json.dump(data, f)
|
41 |
|
42 |
|
43 |
+
|
|
|
|
|
|
|
|
|
44 |
|
45 |
title = '🎵 Annotate audio'
|
46 |
description = '''Choose a sentence that describes audio the best if there's no such sentence please choose `No audio description`'''
|
|
|
48 |
audio_dir = 'AUDIO'
|
49 |
os.makedirs(audio_dir, exist_ok=True)
|
50 |
|
51 |
+
def sample_df():
|
52 |
+
|
53 |
+
gc = gspread.service_account(filename='credentials.json')
|
54 |
+
sh = gc.open('Annotated CC Audio')
|
55 |
+
worksheet = sh.sheet1
|
56 |
+
df = pd.DataFrame(worksheet.get_all_records())
|
57 |
+
sample_df = df[df['caption']==''].sample(1)
|
58 |
+
|
59 |
+
url, audio_url, _, _, full_text, _, _ = sample_df.values[0]
|
60 |
+
audio_path = download_and_save_file(audio_url, audio_dir)
|
61 |
+
full_text = full_text.translate(str.maketrans('', '', string.punctuation))
|
62 |
+
sents = ['\n'.join(wrap(re.sub(r'###audio###\d###', '', s.text), width=70) )for s in nlp(full_text).sents]
|
63 |
+
sents.append('No audio description')
|
64 |
+
return audio_path, audio_url
|
65 |
|
66 |
+
def audio_demo(cap, audio, annotator, audio_url):
|
67 |
+
annotator = annotator if annotator else str(uuid.uuid4())
|
68 |
|
69 |
+
df['caption'].loc[df['audio_url'] == audio_url] = cap
|
70 |
+
df['annotator'].loc[df['audio_url'] == audio_url] = annotator
|
71 |
worksheet.update([df.columns.values.tolist()] + df.values.tolist())
|
72 |
return 'success!'
|
73 |
|
74 |
+
audio_path, audio_url = sample_df()
|
75 |
|
76 |
iface = gr.Interface(
|
77 |
audio_demo,
|
78 |
+
inputs=[gr.Radio(sents, label='audio description'), gr.Audio(audio_path, type="filepath"), gr.Textbox(label='please enter your name'), gr.Textbox(value=audio_url, visible=False)],
|
79 |
outputs=[gr.Textbox(label="output")],
|
80 |
allow_flagging="never",
|
81 |
title=title,
|