David1717 commited on
Commit
08c317d
·
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: Butttler
3
+ emoji: 🦀
4
+ colorFrom: yellow
5
+ colorTo: gray
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
+
11
+ # Load the Whisper model
12
+ model = whisper.load_model("base")
13
+
14
+ # OpenAI API key for GPT
15
+ openai.api_key = 'your_openai_api_key'
16
+
17
+ # Function to convert speech to text using Whisper
18
+ def speech_to_text(audio):
19
+ result = model.transcribe(audio)
20
+ return result['text']
21
+
22
+ # Function to get GPT response
23
+ def gpt_response(text):
24
+ response = openai.Completion.create(
25
+ engine="gpt-3.5-turbo",
26
+ prompt=text,
27
+ max_tokens=100
28
+ )
29
+ return response.choices[0].text.strip()
30
+
31
+ # Function to convert text to speech using Google Text-to-Speech API
32
+ def text_to_speech_google(text):
33
+ from google.cloud import texttospeech
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