Spaces:
Sleeping
Sleeping
Commit
·
5ba294c
1
Parent(s):
f8dec0b
add histories as input to transcribe function
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ LLM_MODEL_NAME = "mistralai/Mistral-7B-Instruct-v0.2"
|
|
13 |
|
14 |
system_prompt = """"<s>[INST] You are Friday, a helpful and conversational AI assistant and You respond with one to two sentences. [/INST] Hello there! I'm friday how can I help you?</s>"""
|
15 |
|
16 |
-
|
17 |
|
18 |
formatted_history = """"""
|
19 |
|
@@ -43,18 +43,17 @@ def generate(user_prompt, temperature=0.1, max_new_tokens=128, top_p=0.95, repet
|
|
43 |
seed=42,
|
44 |
)
|
45 |
|
46 |
-
|
47 |
|
48 |
output = client.text_generation(
|
49 |
-
|
50 |
|
51 |
print(output)
|
52 |
return output
|
53 |
|
54 |
|
55 |
@spaces.GPU(duration=60)
|
56 |
-
def transcribe(audio):
|
57 |
-
global formatted_history, chat_history
|
58 |
|
59 |
sr, y = audio
|
60 |
y = y.astype(np.float32)
|
@@ -66,14 +65,14 @@ def transcribe(audio):
|
|
66 |
|
67 |
llm_response = generate(inputs)
|
68 |
|
69 |
-
|
70 |
|
71 |
formatted_history += f"""Friday: {llm_response}\n"""
|
72 |
|
73 |
audio_response = gTTS(llm_response)
|
74 |
audio_response.save("response.mp3")
|
75 |
|
76 |
-
print(
|
77 |
|
78 |
return "response.mp3", formatted_history
|
79 |
|
@@ -93,7 +92,7 @@ with gr.Blocks() as demo:
|
|
93 |
transcription_box = gr.Textbox(
|
94 |
formatted_history, label="Transcription")
|
95 |
|
96 |
-
transcribe_btn.click(fn=transcribe, inputs=audio_input,
|
97 |
outputs=[output_audio, transcription_box])
|
98 |
|
99 |
|
|
|
13 |
|
14 |
system_prompt = """"<s>[INST] You are Friday, a helpful and conversational AI assistant and You respond with one to two sentences. [/INST] Hello there! I'm friday how can I help you?</s>"""
|
15 |
|
16 |
+
instruct_history = system_prompt + """"""
|
17 |
|
18 |
formatted_history = """"""
|
19 |
|
|
|
43 |
seed=42,
|
44 |
)
|
45 |
|
46 |
+
instruct_history += f"""<s>[INST] {user_prompt} [/INST] """
|
47 |
|
48 |
output = client.text_generation(
|
49 |
+
instruct_history, **generate_kwargs, stream=False, details=False, return_full_text=False)
|
50 |
|
51 |
print(output)
|
52 |
return output
|
53 |
|
54 |
|
55 |
@spaces.GPU(duration=60)
|
56 |
+
def transcribe(audio, formatted_history, instruct_history):
|
|
|
57 |
|
58 |
sr, y = audio
|
59 |
y = y.astype(np.float32)
|
|
|
65 |
|
66 |
llm_response = generate(inputs)
|
67 |
|
68 |
+
instruct_history += f""" {llm_response}</s>"""
|
69 |
|
70 |
formatted_history += f"""Friday: {llm_response}\n"""
|
71 |
|
72 |
audio_response = gTTS(llm_response)
|
73 |
audio_response.save("response.mp3")
|
74 |
|
75 |
+
print(instruct_history)
|
76 |
|
77 |
return "response.mp3", formatted_history
|
78 |
|
|
|
92 |
transcription_box = gr.Textbox(
|
93 |
formatted_history, label="Transcription")
|
94 |
|
95 |
+
transcribe_btn.click(fn=transcribe, inputs=[audio_input, formatted_history, instruct_history],
|
96 |
outputs=[output_audio, transcription_box])
|
97 |
|
98 |
|