Robo2000 commited on
Commit
1c1e957
·
1 Parent(s): 1efcb30

Upload 7 files

Browse files
Files changed (7) hide show
  1. AGICode.txt +12 -0
  2. AIZeroToHeroForHealth.zip +3 -0
  3. README.md +5 -5
  4. README.txt +13 -0
  5. app.py +169 -0
  6. packages.txt +2 -0
  7. requirements.txt +7 -0
AGICode.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AGI GAN Experimental Evolution Process for Training Computer/Camera to Computer/Camera with Dual AI Agents Feeding in Human Input Loop - Toolbar:
2
+ 1. Yggdrasil KB on AI in Health: https://github.com/AaronCWacker/Yggdrasil
3
+ 2. Aaron Wacker 180+ Published Prod AI Demonstration Examples: https://huggingface.co/awacke1
4
+ 3. AINLPCT Biomed Playlist (have AI watch at 1.75 speed): https://www.youtube.com/playlist?list=PLHgX2IExbFov_5_4WfkesR7gnWPHHG-a1
5
+ 4. AINLPCT AGI Medical School (have AI watch at 1.75 speed): https://www.youtube.com/watch?v=r38lXjz3g6M&list=PLHgX2IExbFov_5_4WfkesR7gnWPHHG-a1
6
+ 5. Azure Mountain Sky Album (have AI listen for testing hard NLP understanding of episodic and semantic memory): https://soundcloud.com/aaron-wacker-941819269/sets/azure-mountain-sky
7
+ 6. Discord - AW - Have AI Read Server Activity for:https://discord.com/channels/@me/997514686608191558
8
+ 7. Discord - have AI generate images, feeding NER into prompting
9
+ - Example: /imagine prompt:two laptops with screens showing big brains, with usb cameras pointed at eachother to read eachothers apps and learning in a loop --ar 3840:2160
10
+ 8. RunwayML - composite videos using AI to mash up audio gen, image gen, video gen
11
+ 9. Instacart - Have trained AGI surface products and shop for needed supplies delivery: https://www.instacart.com/store/s?k=usb+camera&search_id=341b0338-6459-41ac-8e14-561cc9164594&page_view_id=ecae9737-e41b-4043-a437-9a554b972898
12
+ 10. Feedback loop - train in examples for composing AGI pipeline parts: https://huggingface.co/AIZero2Hero4Health
AIZeroToHeroForHealth.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8bdb09f32f67e86fa4f8ff371d58c9153e41ef6cff264044886b65811800c641
3
+ size 1328664
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: 02-Gradio ASR
3
- emoji: 😻
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 3.9.1
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
+ title: 1 ASRLiveSpeechRecognition GR
3
+ emoji: 💻
4
+ colorFrom: pink
5
+ colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 3.8.2
8
  app_file: app.py
9
  pinned: false
10
  ---
README.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: 🗣️SpeakNowASR🧠Memory💾Gradio
3
+ emoji: 🗣️🧠💾
4
+ colorFrom: yellow
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.5
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import time
4
+ import librosa
5
+ import soundfile
6
+ import nemo.collections.asr as nemo_asr
7
+ import tempfile
8
+ import os
9
+ import uuid
10
+
11
+ from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
12
+ import torch
13
+
14
+ # PersistDataset -----
15
+ import os
16
+ import csv
17
+ import gradio as gr
18
+ from gradio import inputs, outputs
19
+ import huggingface_hub
20
+ from huggingface_hub import Repository, hf_hub_download, upload_file
21
+ from datetime import datetime
22
+
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/Carddata.csv"
27
+ #DATASET_REPO_ID = "awacke1/Carddata.csv"
28
+ #DATA_FILENAME = "Carddata.csv"
29
+ #DATA_FILE = os.path.join("data", DATA_FILENAME)
30
+ #HF_TOKEN = os.environ.get("HF_TOKEN")
31
+ #SCRIPT = """
32
+
33
+ #<script>
34
+ #if (!window.hasBeenRun) {
35
+ # window.hasBeenRun = true;
36
+ # console.log("should only happen once");
37
+ # document.querySelector("button.submit").click();
38
+ #}
39
+ #</script>
40
+ #"""
41
+
42
+ #try:
43
+ # hf_hub_download(
44
+ # repo_id=DATASET_REPO_ID,
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
+ #def store_message(name: str, message: str):
56
+ # if name and message:
57
+ # with open(DATA_FILE, "a") as csvfile:
58
+ # writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
59
+ # writer.writerow(
60
+ # {"name": name.strip(), "message": message.strip(), "time": str(datetime.now())}
61
+ # )
62
+ # # uncomment line below to begin saving -
63
+ # commit_url = repo.push_to_hub()
64
+ # return ""
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"
84
+ model = BlenderbotForConditionalGeneration.from_pretrained(mname)
85
+ tokenizer = BlenderbotTokenizer.from_pretrained(mname)
86
+
87
+ def take_last_tokens(inputs, note_history, history):
88
+ """Filter the last 128 tokens"""
89
+ if inputs['input_ids'].shape[1] > 128:
90
+ inputs['input_ids'] = torch.tensor([inputs['input_ids'][0][-128:].tolist()])
91
+ inputs['attention_mask'] = torch.tensor([inputs['attention_mask'][0][-128:].tolist()])
92
+ note_history = ['</s> <s>'.join(note_history[0].split('</s> <s>')[2:])]
93
+ history = history[1:]
94
+ return inputs, note_history, history
95
+
96
+ def add_note_to_history(note, note_history):
97
+ """Add a note to the historical information"""
98
+ note_history.append(note)
99
+ note_history = '</s> <s>'.join(note_history)
100
+ return [note_history]
101
+
102
+
103
+ def chat(message, history):
104
+ history = history or []
105
+ if history:
106
+ history_useful = ['</s> <s>'.join([str(a[0])+'</s> <s>'+str(a[1]) for a in history])]
107
+ else:
108
+ history_useful = []
109
+ history_useful = add_note_to_history(message, history_useful)
110
+ inputs = tokenizer(history_useful, return_tensors="pt")
111
+ inputs, history_useful, history = take_last_tokens(inputs, history_useful, history)
112
+ reply_ids = model.generate(**inputs)
113
+ response = tokenizer.batch_decode(reply_ids, skip_special_tokens=True)[0]
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
+ # store_message(message, response) # Save to dataset - uncomment if you uncomment above to save inputs and outputs to your dataset
118
+ return history, history
119
+
120
+
121
+ SAMPLE_RATE = 16000
122
+ model = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained("nvidia/stt_en_conformer_transducer_xlarge")
123
+ model.change_decoding_strategy(None)
124
+ model.eval()
125
+
126
+ def process_audio_file(file):
127
+ data, sr = librosa.load(file)
128
+ if sr != SAMPLE_RATE:
129
+ data = librosa.resample(data, orig_sr=sr, target_sr=SAMPLE_RATE)
130
+ # monochannel
131
+ data = librosa.to_mono(data)
132
+ return data
133
+
134
+
135
+ def transcribe(audio, state = ""):
136
+ if state is None:
137
+ state = ""
138
+ audio_data = process_audio_file(audio)
139
+ with tempfile.TemporaryDirectory() as tmpdir:
140
+ audio_path = os.path.join(tmpdir, f'audio_{uuid.uuid4()}.wav')
141
+ soundfile.write(audio_path, audio_data, SAMPLE_RATE)
142
+ transcriptions = model.transcribe([audio_path])
143
+ if type(transcriptions) == tuple and len(transcriptions) == 2:
144
+ transcriptions = transcriptions[0]
145
+ transcriptions = transcriptions[0]
146
+ # store_message(transcriptions, state) # Save to dataset - uncomment to store into a dataset - hint you will need your HF_TOKEN
147
+ state = state + transcriptions + " "
148
+ return state, state
149
+
150
+ iface = gr.Interface(
151
+ fn=transcribe,
152
+ inputs=[
153
+ gr.Audio(source="microphone", type='filepath', streaming=True),
154
+ "state",
155
+ ],
156
+ outputs=[
157
+ "textbox",
158
+ "state",
159
+ ],
160
+ layout="horizontal",
161
+ theme="huggingface",
162
+ title="🗣️LiveSpeechRecognition🧠Memory💾",
163
+ description=f"Live Automatic Speech Recognition (ASR) with Memory💾 Dataset.",
164
+ allow_flagging='never',
165
+ live=True,
166
+ # article=f"Result Output Saved to Memory💾 Dataset: [{DATASET_REPO_URL}]({DATASET_REPO_URL})"
167
+ article=f"Important Videos to understanding AI and NLP Clinical Terminology, Assessment, and Value Based Care AI include Huggingfaces Course Series here: https://www.youtube.com/c/HuggingFace , AI NLP Innovations in 2022 for Clinical and Mental Health Care here: https://www.youtube.com/watch?v=r38lXjz3g6M&list=PLHgX2IExbFov_5_4WfkesR7gnWPHHG-a1 and this link to see and manage playlist here: https://www.youtube.com/playlist?list=PLHgX2IExbFov_5_4WfkesR7gnWPHHG-a1 Review at your leisure to understand AI and NLP impact to helping the world develop Clinical systems of the future using AI and NLP for Clinical Terminology and alignment to worldwide Value Based Care objectives to help people be healthy."
168
+ )
169
+ iface.launch()
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ffmpeg
2
+ libsndfile1
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ nemo_toolkit[asr]
2
+ transformers
3
+ torch
4
+ gradio
5
+ Werkzeug
6
+ huggingface_hub
7
+ Pillow