Spaces:
Running
Running
Firefly777a
commited on
Commit
•
0a574ec
1
Parent(s):
9dd8d0a
Major Changes changed approach to now do debugging
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
|
2 |
'''
|
3 |
-
This script calls the
|
4 |
'''
|
5 |
import os
|
6 |
os.system("pip install --upgrade pip")
|
@@ -17,27 +17,32 @@ import torch
|
|
17 |
from transformers import AutoModelForCausalLM
|
18 |
from transformers import AutoTokenizer
|
19 |
import time
|
20 |
-
# import streaming.py
|
21 |
-
# from next_word_prediction import GPT2
|
22 |
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
#
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
#
|
33 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# whisper model specification
|
36 |
model = whisper.load_model("tiny")
|
37 |
|
38 |
-
|
39 |
|
40 |
-
def
|
41 |
# load audio data
|
42 |
audio = whisper.load_audio(audio)
|
43 |
# ensure sample is in correct format for inference
|
@@ -54,32 +59,12 @@ def inference(audio, state=""):
|
|
54 |
result = whisper.decode(model, mel, options)
|
55 |
print("result pre gp model from whisper: ", result, ".text ", result.text, "and the data type: ", type(result.text))
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
The predictions follow a few rules:
|
60 |
-
1) The predictions are suggestions of ways to continue the transcript as if someone forgot what the next word was.
|
61 |
-
2) The predictions do not repeat themselves.
|
62 |
-
3) The predictions focus on suggesting nouns, adjectives, and verbs.
|
63 |
-
4) The predictions are related to the context in the transcript.
|
64 |
-
|
65 |
-
EXAMPLES:
|
66 |
-
Transcript: Tomorrow night we're going out to
|
67 |
-
Prediction: The Movies, A Restaurant, A Baseball Game, The Theater, A Party for a friend
|
68 |
-
Transcript: I would like to order a cheeseburger with a side of
|
69 |
-
Prediction: Frnech fries, Milkshake, Apple slices, Side salad, Extra katsup
|
70 |
-
Transcript: My friend Savanah is
|
71 |
-
Prediction: An elecrical engineer, A marine biologist, A classical musician
|
72 |
-
Transcript: I need to buy a birthday
|
73 |
-
Prediction: Present, Gift, Cake, Card
|
74 |
-
Transcript: """
|
75 |
-
text = PROMPT + result.text + "\nPrediction: "
|
76 |
-
|
77 |
-
openai.api_key = os.environ["Openai_APIkey"]
|
78 |
|
79 |
response = openai.Completion.create(
|
80 |
-
model=
|
81 |
prompt=text,
|
82 |
-
temperature=
|
83 |
max_tokens=8,
|
84 |
n=5)
|
85 |
|
@@ -97,19 +82,16 @@ Transcript: """
|
|
97 |
infers = list(map(lambda x: x.replace("\n", ""), temp))
|
98 |
#infered = list(map(lambda x: x.split(','), infers))
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
# result.text
|
104 |
-
#return getText, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
105 |
-
return result.text, state, infers
|
106 |
-
|
107 |
-
|
108 |
|
109 |
# get audio from microphone
|
110 |
gr.Interface(
|
111 |
-
fn=
|
112 |
-
inputs=[gr.inputs.Audio(source="microphone", type="filepath"),
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
'''
|
3 |
+
This script calls the model from openai api to predict the next few words.
|
4 |
'''
|
5 |
import os
|
6 |
os.system("pip install --upgrade pip")
|
|
|
17 |
from transformers import AutoModelForCausalLM
|
18 |
from transformers import AutoTokenizer
|
19 |
import time
|
|
|
|
|
20 |
|
21 |
+
# PROMPT = """This is a tool for helping someone with memory issues remember the next word.
|
22 |
|
23 |
+
# The predictions follow a few rules:
|
24 |
+
# 1) The predictions are suggestions of ways to continue the transcript as if someone forgot what the next word was.
|
25 |
+
# 2) The predictions do not repeat themselves.
|
26 |
+
# 3) The predictions focus on suggesting nouns, adjectives, and verbs.
|
27 |
+
# 4) The predictions are related to the context in the transcript.
|
28 |
+
|
29 |
+
# EXAMPLES:
|
30 |
+
# Transcript: Tomorrow night we're going out to
|
31 |
+
# Prediction: The Movies, A Restaurant, A Baseball Game, The Theater, A Party for a friend
|
32 |
+
# Transcript: I would like to order a cheeseburger with a side of
|
33 |
+
# Prediction: Frnech fries, Milkshake, Apple slices, Side salad, Extra katsup
|
34 |
+
# Transcript: My friend Savanah is
|
35 |
+
# Prediction: An elecrical engineer, A marine biologist, A classical musician
|
36 |
+
# Transcript: I need to buy a birthday
|
37 |
+
# Prediction: Present, Gift, Cake, Card
|
38 |
+
# Transcript: """
|
39 |
|
40 |
# whisper model specification
|
41 |
model = whisper.load_model("tiny")
|
42 |
|
43 |
+
openai.api_key = os.environ["Openai_APIkey"]
|
44 |
|
45 |
+
def debug_inference(audio, prompt, model, temperature, state=""):
|
46 |
# load audio data
|
47 |
audio = whisper.load_audio(audio)
|
48 |
# ensure sample is in correct format for inference
|
|
|
59 |
result = whisper.decode(model, mel, options)
|
60 |
print("result pre gp model from whisper: ", result, ".text ", result.text, "and the data type: ", type(result.text))
|
61 |
|
62 |
+
text = prompt + result.text + "\nPrediction: "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
response = openai.Completion.create(
|
65 |
+
model=model,
|
66 |
prompt=text,
|
67 |
+
temperature=temperature,
|
68 |
max_tokens=8,
|
69 |
n=5)
|
70 |
|
|
|
82 |
infers = list(map(lambda x: x.replace("\n", ""), temp))
|
83 |
#infered = list(map(lambda x: x.split(','), infers))
|
84 |
|
85 |
+
return result.text, state, infers, text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# get audio from microphone
|
88 |
gr.Interface(
|
89 |
+
fn=debug_inference,
|
90 |
+
inputs=[gr.inputs.Audio(source="microphone", type="filepath"),
|
91 |
+
gr.inputs.Textbox(lines=15, placeholder="Enter a prompt here"),
|
92 |
+
gr.inputs.Dropdown(["text-ada-001", "text-davinci-002", "text-davinci-003", "gpt-3.5-turbo"], label="Model"),
|
93 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.8, step=0.1, label="Temperature"),
|
94 |
+
"state"
|
95 |
+
],
|
96 |
+
outputs=["textbox","state","textbox", "textbox"],
|
97 |
+
live=True).launch()
|