sudip1987 commited on
Commit
3ae932d
Β·
verified Β·
1 Parent(s): 611159f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ from langchain.chat_models import ChatOpenAI
3
+ from langchain.prompts import PromptTemplate
4
+ from langchain.chains import LLMChain
5
+
6
+
7
+ # Step 1: Load the Whisper model
8
+ model = whisper.load_model("base")
9
+
10
+ # Step 2: Function to convert speech to text
11
+ def speech_to_text(audio_file_path):
12
+ result = model.transcribe(audio_file_path)
13
+ return result["text"]
14
+
15
+ # Step 3: Use LangChain for further processing
16
+ def process_text_with_langchain(text):
17
+ # Define a simple prompt template and LLM
18
+ prompt_template = "Translate the following text to French: {text}"
19
+ prompt = PromptTemplate(input_variables=["text"], template=prompt_template)
20
+
21
+ llm = ChatOpenAI(model="gpt-4")
22
+ chain = LLMChain(llm=llm, prompt=prompt)
23
+
24
+ # Generate output
25
+ return chain.run(text)
26
+
27
+ # Example usage
28
+ audio_file_path = "path_to_your_audio_file.wav"
29
+ text = speech_to_text(audio_file_path)
30
+ print("Transcribed Text:", text)
31
+
32
+ # Further processing with LangChain
33
+ translated_text = process_text_with_langchain(text)
34
+ print("Translated Text:", translated_text)
35
+