Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,18 +9,14 @@ def alexa(audio):
|
|
9 |
return speech
|
10 |
|
11 |
def speech_to_text(audio):
|
12 |
-
audio_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
|
13 |
-
|
14 |
-
raise gr.Error("Submit an audio file")
|
15 |
-
else:
|
16 |
-
text = audio_to_text(audio)["text"]
|
17 |
return text
|
18 |
|
19 |
def text_generation(text):
|
20 |
model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-128k-instruct",
|
21 |
-
|
22 |
-
trust_remote_code=True
|
23 |
-
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct")
|
24 |
|
25 |
messages = [
|
26 |
{"role": "user", "content": text}
|
@@ -33,8 +29,8 @@ def text_generation(text):
|
|
33 |
"do_sample": True,
|
34 |
}
|
35 |
|
36 |
-
text_gen= pipeline("text-generation", model=
|
37 |
-
response = text_gen(messages,
|
38 |
return response[0]["generated_text"]
|
39 |
|
40 |
def text_to_speech(text):
|
@@ -45,4 +41,4 @@ def text_to_speech(text):
|
|
45 |
gr.Interface(
|
46 |
fn=alexa,
|
47 |
inputs=gr.Audio(type="filepath"),
|
48 |
-
outputs=[gr.Audio(label="Audio", type="numpy", autoplay=
|
|
|
9 |
return speech
|
10 |
|
11 |
def speech_to_text(audio):
|
12 |
+
audio_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
|
13 |
+
text = audio_to_text(audio,generate_kwargs={"task": "transcribe", "language": "english"})["text"]
|
|
|
|
|
|
|
14 |
return text
|
15 |
|
16 |
def text_generation(text):
|
17 |
model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-128k-instruct",
|
18 |
+
trust_remote_code=True)
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct"), trust_remote_code=True)
|
|
|
20 |
|
21 |
messages = [
|
22 |
{"role": "user", "content": text}
|
|
|
29 |
"do_sample": True,
|
30 |
}
|
31 |
|
32 |
+
text_gen= pipeline("text-generation", model=model, tokenizer=tokenizer, trust_remote_code = True)
|
33 |
+
response = text_gen(messages, generation_args)
|
34 |
return response[0]["generated_text"]
|
35 |
|
36 |
def text_to_speech(text):
|
|
|
41 |
gr.Interface(
|
42 |
fn=alexa,
|
43 |
inputs=gr.Audio(type="filepath"),
|
44 |
+
outputs=[gr.Audio(label="Audio", type="numpy", autoplay=False)]).launch()
|