LalitMahale commited on
Commit
e95de35
·
1 Parent(s): 221b989

audio_model_added

Browse files
Files changed (3) hide show
  1. app.py +14 -2
  2. main.py +16 -1
  3. requirements.txt +1 -0
app.py CHANGED
@@ -1,11 +1,12 @@
1
- from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel
3
  from deep_translator import GoogleTranslator
4
  from fastapi.responses import JSONResponse
5
- from main import process
6
  # Create the FastAPI app instance
7
  app = FastAPI()
8
 
 
9
  # Root endpoint
10
  @app.get("/")
11
  async def home():
@@ -31,3 +32,14 @@ async def chatbot(text: str = ""):
31
  result = process(user_query=text)
32
  return {"result": result}
33
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException,UploadFile,File
2
  from pydantic import BaseModel
3
  from deep_translator import GoogleTranslator
4
  from fastapi.responses import JSONResponse
5
+ from main import process,audio_process
6
  # Create the FastAPI app instance
7
  app = FastAPI()
8
 
9
+
10
  # Root endpoint
11
  @app.get("/")
12
  async def home():
 
32
  result = process(user_query=text)
33
  return {"result": result}
34
 
35
+ @app.post("/audio_chat")
36
+ async def chatbot(audio: UploadFile = File(...)):
37
+ if not audio:
38
+ raise HTTPException(status_code=400, detail="No audio file provided")
39
+
40
+ # Example of processing the audio file (you should replace `process` with your actual function)
41
+ try:
42
+ result = audio_process(audio.file) # Replace with actual audio processing logic
43
+ return {"result": result}
44
+ except Exception as e:
45
+ raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
main.py CHANGED
@@ -5,6 +5,7 @@ import random
5
  import pickle
6
  import os
7
  from utils.rag import RAG
 
8
 
9
 
10
  # def dump_user_question(query):
@@ -43,9 +44,23 @@ def process(user_query:str):
43
  return final_output
44
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  if __name__ == "__main__":
48
- pass
 
49
  # for _ in range(3):
50
  # user = input("How can i help you :? \n")
51
  # result = process(user)
 
5
  import pickle
6
  import os
7
  from utils.rag import RAG
8
+ from faster_whisper import WhisperModel
9
 
10
 
11
  # def dump_user_question(query):
 
44
  return final_output
45
 
46
 
47
+ def audio_process(audio):
48
+ try:
49
+ model = WhisperModel("medium.en")
50
+ segments, info = model.transcribe(audio)
51
+ transcription = " ".join([seg.text for seg in segments])
52
+ result = process(user_query=transcription)
53
+ return result
54
+ except Exception as e:
55
+ print("Error:", e)
56
+ return str(e)
57
+
58
+
59
+
60
 
61
  if __name__ == "__main__":
62
+ res = audio_process(r"C:\Users\lalit\Documents\Sound recordings\who_is_lalit.m4a")
63
+ print(res)
64
  # for _ in range(3):
65
  # user = input("How can i help you :? \n")
66
  # result = process(user)
requirements.txt CHANGED
@@ -5,4 +5,5 @@ sentence_transformers
5
  langchain
6
  langchain-community
7
  langchain-google-genai
 
8
 
 
5
  langchain
6
  langchain-community
7
  langchain-google-genai
8
+ faster_whisper
9