Prajith04 commited on
Commit
c926cd5
1 Parent(s): 48d54cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -41
app.py CHANGED
@@ -1,51 +1,22 @@
1
  import streamlit as st
2
- import sounddevice as sd
3
- import soundfile as sf
4
- from faster_whisper import WhisperModel
5
- import io
6
- import os
7
  from langchain_community.llms import Ollama
8
- import pyttsx3
9
- # Set environment variable to handle duplicate libraries
10
- os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
11
 
12
- # Initialize WhisperModel and Ollama
13
- model_size = "base.en"
14
- model = WhisperModel(model_size, device="cpu", compute_type="int8", num_workers=5)
15
  llm = Ollama(model="tinyllama")
16
 
17
- # Initialize text-to-speech engine
18
- engine = pyttsx3.init('sapi5')
19
- voices = engine.getProperty('voices')
20
- engine.setProperty('voice',voices[0].id)
21
- engine.setProperty('rate',180)
22
 
23
- def speak(audio):
24
- engine.say(audio)
25
- engine.runAndWait()
26
 
27
- # Record and transcribe audio
28
- audio_data = st.audio("recorded_audio.wav", format="audio/wav", start_time=0)
29
- if st.button("Record"):
30
- with st.spinner("Recording..."):
31
- recorded_audio = sd.rec(int(5 * 44100), samplerate=44100, channels=2, dtype="int16")
32
- sd.wait()
33
- sf.write("recorded_audio.wav", recorded_audio, samplerate=44100)
34
-
35
- st.audio("recorded_audio.wav", format="audio/wav", start_time=0)
36
-
37
- # Transcribe audio and speak response
38
- with open("recorded_audio.wav", "rb") as audio_file:
39
- segments,info= model.transcribe(io.BytesIO(audio_file.read()), beam_size=10)
40
- for segment in segments:
41
- prompt=segment.text
42
- print(prompt)
43
- st.text(prompt)
44
  if prompt:
 
45
  response = llm.invoke(prompt)
46
- st.success("Response: " + response)
47
- speak(response)
48
- st.stop()
49
  else:
50
- st.error("Failed to transcribe audio.")
51
-
 
1
  import streamlit as st
 
 
 
 
 
2
  from langchain_community.llms import Ollama
 
 
 
3
 
4
+ # Initialize the language model
 
 
5
  llm = Ollama(model="tinyllama")
6
 
7
+ # Streamlit UI elements
8
+ st.title("Language Model Invocation")
9
+ st.write("Enter a prompt to get a response from the language model.")
 
 
10
 
11
+ # Text input for prompt
12
+ prompt = st.text_input("Enter a prompt:")
 
13
 
14
+ # Button to invoke the model
15
+ if st.button("Submit"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  if prompt:
17
+ # Generate the response
18
  response = llm.invoke(prompt)
19
+ st.write("Response:")
20
+ st.write(response)
 
21
  else:
22
+ st.write("Please enter a prompt.")