bhagaskara commited on
Commit
3578afb
·
verified ·
1 Parent(s): abba247
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import speech_recognition as srec
3
+ from gtts import gTTS
4
+ import os
5
+ import google.generativeai as genai
6
+ from playsound import playsound
7
+
8
+ # Google API Key (Replace with your actual key)
9
+ GOOGLE_API_KEY = 'AIzaSyAc0urJKyqWaZsHc9ayF37IHVIeYQavIV0'
10
+
11
+ # Configure Google AI Generative Model
12
+ genai.configure(api_key=GOOGLE_API_KEY)
13
+ model = genai.GenerativeModel('gemini-pro')
14
+
15
+
16
+ def perintah():
17
+ mendengar = srec.Recognizer()
18
+ with srec.Microphone() as source:
19
+ st.write('Mendengarkan....')
20
+ suara = mendengar.listen(source, phrase_time_limit=15)
21
+ try:
22
+ st.write('Diterima...')
23
+ dengar = mendengar.recognize_google(suara, language='id-ID')
24
+ st.write(f'Anda: {dengar}')
25
+
26
+ # Generate response using Gemini Pro generative model
27
+ chat = model.start_chat()
28
+ response = chat.send_message(f'{dengar}')
29
+ st.write(f'Nutrikara: {response.text}')
30
+
31
+ return response.text
32
+ except Exception as e:
33
+ st.write(f'Error: {e}')
34
+ return None
35
+
36
+
37
+ def ngomong(teks):
38
+ bahasa = 'id'
39
+ namafile = 'Ngomong.mp3'
40
+ teks_bersih = teks.replace('*', '|')
41
+ def reading():
42
+ suara = gTTS(text=teks_bersih, lang=bahasa, slow=False)
43
+ suara.save(namafile)
44
+ playsound(namafile)
45
+ reading()
46
+
47
+
48
+ def run_michelle():
49
+ layanan = perintah()
50
+ if layanan:
51
+ ngomong(layanan)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ st.subheader("Konsultasi Gizi Nutrikara")
56
+ st.write("Klik tombol di bawah ini untuk mulai menggunakan:")
57
+
58
+ if st.button("Mulai Konsultasi"):
59
+ while True:
60
+ run_michelle()
61
+ layanan = perintah()
62
+ break