Angelo25 commited on
Commit
7157d41
·
verified ·
1 Parent(s): a37ced2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -9,7 +9,7 @@ whisper_tokenizer = AutoTokenizer.from_pretrained("openai/whisper-tiny")
9
 
10
  llm_model = AutoModelForCausalLM.from_pretrained(
11
  "microsoft/Phi-3-mini-4k-instruct",
12
- device_map="cuda",
13
  torch_dtype="auto",
14
  trust_remote_code=True)
15
  llm_tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
@@ -34,20 +34,15 @@ def generate_text(prompt):
34
  return generated_text
35
 
36
  def text_to_speech(text):
37
- speech = vits_tts(text)[0]['audio']
 
38
  return speech
39
 
40
  # Create Gradio interface
41
- audio_input = gr.Audio(label="Record your voice", sources="microphone", preprocess=audio_to_text)
42
  text_output = gr.Textbox(label="Transcribed Text")
43
- gr.Interface(
44
- generate_text,
45
- inputs=audio_input,
46
- outputs=gr.Textbox(label="Generated Text")
47
- ).launch()
48
-
49
  gr.Interface(
50
  text_to_speech,
51
- inputs=gr.Textbox(lines=5, label="Enter your text"),
52
- outputs=gr.Audio(label="Speech")
53
- ).launch()
 
9
 
10
  llm_model = AutoModelForCausalLM.from_pretrained(
11
  "microsoft/Phi-3-mini-4k-instruct",
12
+ device_map="cpu",
13
  torch_dtype="auto",
14
  trust_remote_code=True)
15
  llm_tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
 
34
  return generated_text
35
 
36
  def text_to_speech(text):
37
+ generated_text = phi3_mini_4k(text, max_length=50, do_sample=True)[0]['generated_text']
38
+ speech = vits_tts(generated_text)[0]['audio']
39
  return speech
40
 
41
  # Create Gradio interface
42
+ audio_input = gr.Audio(label="Can I Help You?", sources="microphone")
43
  text_output = gr.Textbox(label="Transcribed Text")
 
 
 
 
 
 
44
  gr.Interface(
45
  text_to_speech,
46
+ inputs=audio_input,
47
+ outputs=gr.Audio(label="Answer:"),
48
+ title="MyAlexa AI Assistant").launch(inbrowser=True)