David1717 commited on
Commit
51598fd
·
verified ·
0 Parent(s):

initial commit

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +12 -0
  3. app.py +76 -0
  4. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Buttler
3
+ emoji: 📊
4
+ colorFrom: gray
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 5.1.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This Gradio app creates a conversation pipeline that includes speech-to-text using the Whisper model,
2
+ # GPT response generation, and text-to-speech using the Google Text-to-Speech API.
3
+ # The app uses the microphone input to capture audio, processes it through the pipeline, and returns the GPT response as text and audio.
4
+
5
+ import gradio as gr
6
+ import openai
7
+ import whisper
8
+ import numpy as np
9
+ import os
10
+ from google.cloud import texttospeech
11
+
12
+ # Load the Whisper model
13
+ model = whisper.load_model("base")
14
+
15
+ # OpenAI API key for GPT
16
+ openai.api_key = 'your_openai_api_key'
17
+
18
+ # Function to convert speech to text using Whisper
19
+ def speech_to_text(audio):
20
+ result = model.transcribe(audio)
21
+ return result['text']
22
+
23
+ # Function to get GPT response
24
+ def gpt_response(text):
25
+ response = openai.Completion.create(
26
+ engine="text-davinci-003", # Use a valid engine name for GPT-3
27
+ prompt=text,
28
+ max_tokens=100
29
+ )
30
+ return response.choices[0].text.strip()
31
+
32
+ # Function to convert text to speech using Google Text-to-Speech API
33
+ def text_to_speech_google(text):
34
+ client = texttospeech.TextToSpeechClient()
35
+ input_text = texttospeech.SynthesisInput(text=text)
36
+
37
+ voice = texttospeech.VoiceSelectionParams(
38
+ language_code="en-US",
39
+ ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
40
+ )
41
+
42
+ audio_config = texttospeech.AudioConfig(
43
+ audio_encoding=texttospeech.AudioEncoding.MP3
44
+ )
45
+
46
+ response = client.synthesize_speech(
47
+ input=input_text, voice=voice, audio_config=audio_config
48
+ )
49
+
50
+ # Save the audio response to a file
51
+ output_path = "output.mp3"
52
+ with open(output_path, "wb") as out:
53
+ out.write(response.audio_content)
54
+ return output_path
55
+
56
+ # Function to handle the entire conversation pipeline
57
+ def conversation_pipeline(audio):
58
+ # Step 1: Convert speech to text
59
+ text = speech_to_text(audio)
60
+
61
+ # Step 2: Get GPT response
62
+ response_text = gpt_response(text)
63
+
64
+ # Step 3: Convert GPT response to speech
65
+ response_audio = text_to_speech_google(response_text)
66
+
67
+ return response_text, response_audio
68
+
69
+ # Gradio interface
70
+ demo = gr.Interface(
71
+ fn=conversation_pipeline,
72
+ inputs=gr.Audio(source="microphone", type="filepath"),
73
+ outputs=[gr.Textbox(label="GPT Response"), gr.Audio(label="GPT Response Audio", type="filepath", autoplay=True)]
74
+ )
75
+
76
+ demo.launch(show_error=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ numpy
2
+ matplotlib