Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,61 +23,36 @@ from datetime import datetime
|
|
| 23 |
# ---------------------------------------------
|
| 24 |
# Dataset and Token links - change awacke1 to your own HF id, and add a HF_TOKEN copy to your repo for write permissions
|
| 25 |
# This should allow you to save your results to your own Dataset hosted on HF. ---
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# filename=DATA_FILENAME,
|
| 46 |
-
# cache_dir=DATA_DIRNAME,
|
| 47 |
-
# force_filename=DATA_FILENAME
|
| 48 |
-
# )
|
| 49 |
-
#except:
|
| 50 |
-
# print("file not found")
|
| 51 |
-
#repo = Repository(
|
| 52 |
-
# local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
| 53 |
-
#)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
#iface = gr.Interface(
|
| 67 |
-
# store_message,
|
| 68 |
-
# [
|
| 69 |
-
# inputs.Textbox(placeholder="Your name"),
|
| 70 |
-
# inputs.Textbox(placeholder="Your message", lines=2),
|
| 71 |
-
# ],
|
| 72 |
-
# "html",
|
| 73 |
-
# css="""
|
| 74 |
-
# .message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
|
| 75 |
-
# """,
|
| 76 |
-
# title="Reading/writing to a HuggingFace dataset repo from Spaces",
|
| 77 |
-
# description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
|
| 78 |
-
# article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
|
| 79 |
-
#)
|
| 80 |
-
|
| 81 |
|
| 82 |
# main -------------------------
|
| 83 |
mname = "facebook/blenderbot-400M-distill"
|
|
@@ -114,7 +89,7 @@ def chat(message, history):
|
|
| 114 |
history_useful = add_note_to_history(response, history_useful)
|
| 115 |
list_history = history_useful[0].split('</s> <s>')
|
| 116 |
history.append((list_history[-2], list_history[-1]))
|
| 117 |
-
|
| 118 |
return history, history
|
| 119 |
|
| 120 |
|
|
@@ -143,7 +118,7 @@ def transcribe(audio, state = ""):
|
|
| 143 |
if type(transcriptions) == tuple and len(transcriptions) == 2:
|
| 144 |
transcriptions = transcriptions[0]
|
| 145 |
transcriptions = transcriptions[0]
|
| 146 |
-
|
| 147 |
state = state + transcriptions + " "
|
| 148 |
return state, state
|
| 149 |
|
|
@@ -159,10 +134,10 @@ iface = gr.Interface(
|
|
| 159 |
],
|
| 160 |
layout="horizontal",
|
| 161 |
theme="huggingface",
|
| 162 |
-
title="🗣️
|
| 163 |
description=f"Live Automatic Speech Recognition (ASR) with Memory💾 Dataset.",
|
| 164 |
allow_flagging='never',
|
| 165 |
live=True,
|
| 166 |
-
|
| 167 |
)
|
| 168 |
iface.launch()
|
|
|
|
| 23 |
# ---------------------------------------------
|
| 24 |
# Dataset and Token links - change awacke1 to your own HF id, and add a HF_TOKEN copy to your repo for write permissions
|
| 25 |
# This should allow you to save your results to your own Dataset hosted on HF. ---
|
| 26 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/awacke1/ASRLive.csv"
|
| 27 |
+
DATASET_REPO_ID = "awacke1/ASRLive.csv"
|
| 28 |
+
DATA_FILENAME = "ASRLive.csv"
|
| 29 |
+
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 30 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 31 |
+
SCRIPT = """
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
hf_hub_download(
|
| 35 |
+
repo_id=DATASET_REPO_ID,
|
| 36 |
+
filename=DATA_FILENAME,
|
| 37 |
+
cache_dir=DATA_DIRNAME,
|
| 38 |
+
force_filename=DATA_FILENAME
|
| 39 |
+
)
|
| 40 |
+
except:
|
| 41 |
+
print("file not found")
|
| 42 |
+
repo = Repository(
|
| 43 |
+
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
| 44 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
def store_message(name: str, message: str):
|
| 47 |
+
if name and message:
|
| 48 |
+
with open(DATA_FILE, "a") as csvfile:
|
| 49 |
+
writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
|
| 50 |
+
writer.writerow(
|
| 51 |
+
{"name": name.strip(), "message": message.strip(), "time": str(datetime.now())}
|
| 52 |
+
)
|
| 53 |
+
# uncomment line below to begin saving -
|
| 54 |
+
commit_url = repo.push_to_hub()
|
| 55 |
+
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# main -------------------------
|
| 58 |
mname = "facebook/blenderbot-400M-distill"
|
|
|
|
| 89 |
history_useful = add_note_to_history(response, history_useful)
|
| 90 |
list_history = history_useful[0].split('</s> <s>')
|
| 91 |
history.append((list_history[-2], list_history[-1]))
|
| 92 |
+
store_message(message, response) # Save to dataset - uncomment if you uncomment above to save inputs and outputs to your dataset
|
| 93 |
return history, history
|
| 94 |
|
| 95 |
|
|
|
|
| 118 |
if type(transcriptions) == tuple and len(transcriptions) == 2:
|
| 119 |
transcriptions = transcriptions[0]
|
| 120 |
transcriptions = transcriptions[0]
|
| 121 |
+
store_message(transcriptions, state) # Save to dataset - uncomment to store into a dataset - hint you will need your HF_TOKEN
|
| 122 |
state = state + transcriptions + " "
|
| 123 |
return state, state
|
| 124 |
|
|
|
|
| 134 |
],
|
| 135 |
layout="horizontal",
|
| 136 |
theme="huggingface",
|
| 137 |
+
title="🗣️ASR-Live🧠Memory💾",
|
| 138 |
description=f"Live Automatic Speech Recognition (ASR) with Memory💾 Dataset.",
|
| 139 |
allow_flagging='never',
|
| 140 |
live=True,
|
| 141 |
+
article=f"Result Output Saved to Memory💾 Dataset: [{DATASET_REPO_URL}]({DATASET_REPO_URL})"
|
| 142 |
)
|
| 143 |
iface.launch()
|