Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- src/__init__.py +0 -0
- src/__pycache__/__init__.cpython-310.pyc +0 -0
- src/__pycache__/__init__.cpython-38.pyc +0 -0
- src/__pycache__/__init__.cpython-39.pyc +0 -0
- src/__pycache__/helper.cpython-310.pyc +0 -0
- src/__pycache__/helper.cpython-38.pyc +0 -0
- src/__pycache__/helper.cpython-39.pyc +0 -0
- src/helper.py +52 -0
src/__init__.py
ADDED
File without changes
|
src/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (150 Bytes). View file
|
|
src/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (146 Bytes). View file
|
|
src/__pycache__/__init__.cpython-39.pyc
ADDED
Binary file (146 Bytes). View file
|
|
src/__pycache__/helper.cpython-310.pyc
ADDED
Binary file (1.5 kB). View file
|
|
src/__pycache__/helper.cpython-38.pyc
ADDED
Binary file (1.41 kB). View file
|
|
src/__pycache__/helper.cpython-39.pyc
ADDED
Binary file (1.43 kB). View file
|
|
src/helper.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import speech_recognition as sr
|
2 |
+
import google.generativeai as genai
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import os
|
5 |
+
from gtts import gTTS
|
6 |
+
import re
|
7 |
+
|
8 |
+
print("perfect!!")
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
GOOGLE_API_KEY=os.getenv("GOOGLE_API_KEY")
|
12 |
+
os.environ["GOOGLE_API_KEY"]=GOOGLE_API_KEY
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
def voice_input():
|
17 |
+
r=sr.Recognizer()
|
18 |
+
|
19 |
+
with sr.Microphone() as source:
|
20 |
+
print("listening...")
|
21 |
+
audio=r.listen(source)
|
22 |
+
try:
|
23 |
+
text=r.recognize_google(audio)
|
24 |
+
print("you said: ", text)
|
25 |
+
return text
|
26 |
+
except sr.UnknownValueError:
|
27 |
+
print("sorry, could not understand the audio")
|
28 |
+
except sr.RequestError as e:
|
29 |
+
print("could not request result from google speech recognition service: {0}".format(e))
|
30 |
+
|
31 |
+
|
32 |
+
def text_to_speech(text):
|
33 |
+
tts=gTTS(text=text, lang="en")
|
34 |
+
|
35 |
+
#save the speech from the given text in the mp3 format
|
36 |
+
tts.save("speech.mp3")
|
37 |
+
|
38 |
+
def llm_model_object(user_text):
|
39 |
+
#model = "models/gemini-pro"
|
40 |
+
|
41 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
42 |
+
|
43 |
+
model = genai.GenerativeModel('gemini-pro')
|
44 |
+
|
45 |
+
response=model.generate_content(user_text)
|
46 |
+
|
47 |
+
result=response.text
|
48 |
+
|
49 |
+
# Remove '**' formatting
|
50 |
+
clean_result = re.sub(r'\*{1,2}', '', result)
|
51 |
+
|
52 |
+
return clean_result
|