LalitMahale
commited on
Commit
·
ef93b5e
1
Parent(s):
eed80a2
change
Browse files- Dockerfile +3 -0
- app.py +25 -15
- main.py +2 -15
Dockerfile
CHANGED
@@ -13,6 +13,9 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
13 |
# Set environment variable for Hugging Face cache (optional but recommended)
|
14 |
ENV TRANSFORMERS_CACHE=/tmp/huggingface_cache
|
15 |
|
|
|
|
|
|
|
16 |
# Expose the port the app will run on (7860 in this case)
|
17 |
EXPOSE 7860
|
18 |
|
|
|
13 |
# Set environment variable for Hugging Face cache (optional but recommended)
|
14 |
ENV TRANSFORMERS_CACHE=/tmp/huggingface_cache
|
15 |
|
16 |
+
# Create the cache directory and make sure it's writable
|
17 |
+
RUN mkdir -p /tmp/huggingface_cache && chmod -R 777 /tmp/huggingface_cache
|
18 |
+
|
19 |
# Expose the port the app will run on (7860 in this case)
|
20 |
EXPOSE 7860
|
21 |
|
app.py
CHANGED
@@ -4,6 +4,8 @@ from deep_translator import GoogleTranslator
|
|
4 |
from fastapi.responses import JSONResponse
|
5 |
import os
|
6 |
from main import process,audio_process
|
|
|
|
|
7 |
# Create the FastAPI app instance
|
8 |
os.makedirs("/tmp/huggingface_cache", exist_ok=True)
|
9 |
os.environ["HF_HOME"] = "/tmp/huggingface_cache"
|
@@ -11,38 +13,46 @@ os.environ["HF_HOME"] = "/tmp/huggingface_cache"
|
|
11 |
|
12 |
app = FastAPI()
|
13 |
|
14 |
-
|
15 |
# Root endpoint
|
16 |
@app.get("/")
|
17 |
async def home():
|
18 |
-
return {"message": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Translate endpoint that accepts a query parameter 'text'
|
21 |
@app.get("/translate")
|
22 |
-
async def translate(text: str = ""):
|
23 |
-
if not text:
|
24 |
-
raise HTTPException(status_code=400, detail="No text provided")
|
25 |
-
|
26 |
-
# Perform translation using deep_translator
|
27 |
translator = GoogleTranslator(source="auto", target="mr")
|
28 |
result = translator.translate(text)
|
29 |
-
|
30 |
return {"result": result}
|
31 |
|
32 |
@app.get("/chatbot")
|
33 |
-
async def chatbot(text: str = ""):
|
34 |
-
if not text:
|
35 |
raise HTTPException(status_code=400, detail="No text provided")
|
36 |
-
|
37 |
result = process(user_query=text)
|
38 |
return {"result": result}
|
39 |
|
40 |
@app.post("/audio_chat")
|
41 |
-
async def audio_chat(audio: UploadFile = File(...)):
|
42 |
-
if not audio:
|
43 |
raise HTTPException(status_code=400, detail="No audio file provided")
|
44 |
-
|
45 |
-
# Example of processing the audio file (you should replace `process` with your actual function)
|
46 |
try:
|
47 |
result = audio_process(audio.file) # Replace with actual audio processing logic
|
48 |
return {"result": result}
|
|
|
4 |
from fastapi.responses import JSONResponse
|
5 |
import os
|
6 |
from main import process,audio_process
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
load_dotenv()
|
9 |
# Create the FastAPI app instance
|
10 |
os.makedirs("/tmp/huggingface_cache", exist_ok=True)
|
11 |
os.environ["HF_HOME"] = "/tmp/huggingface_cache"
|
|
|
13 |
|
14 |
app = FastAPI()
|
15 |
|
|
|
16 |
# Root endpoint
|
17 |
@app.get("/")
|
18 |
async def home():
|
19 |
+
return {"message": "Testing_api"}
|
20 |
+
|
21 |
+
import os
|
22 |
+
from fastapi import FastAPI, HTTPException, UploadFile, File
|
23 |
+
from deep_translator import GoogleTranslator
|
24 |
+
|
25 |
+
app = FastAPI()
|
26 |
+
|
27 |
+
# Token verification function
|
28 |
+
def verify_token(token: str):
|
29 |
+
if token != os.getenv("TOKEN"):
|
30 |
+
raise HTTPException(status_code=401, detail="Token not matched")
|
31 |
|
32 |
# Translate endpoint that accepts a query parameter 'text'
|
33 |
@app.get("/translate")
|
34 |
+
async def translate(text: str = "", token: str = ""):
|
35 |
+
if not text or not token:
|
36 |
+
raise HTTPException(status_code=400, detail="No text or token provided")
|
37 |
+
verify_token(token)
|
|
|
38 |
translator = GoogleTranslator(source="auto", target="mr")
|
39 |
result = translator.translate(text)
|
40 |
+
|
41 |
return {"result": result}
|
42 |
|
43 |
@app.get("/chatbot")
|
44 |
+
async def chatbot(text: str = "", token: str = ""):
|
45 |
+
if not text or not token:
|
46 |
raise HTTPException(status_code=400, detail="No text provided")
|
47 |
+
verify_token(token)
|
48 |
result = process(user_query=text)
|
49 |
return {"result": result}
|
50 |
|
51 |
@app.post("/audio_chat")
|
52 |
+
async def audio_chat(audio: UploadFile = File(...), token: str = ""):
|
53 |
+
if not audio or not token:
|
54 |
raise HTTPException(status_code=400, detail="No audio file provided")
|
55 |
+
verify_token(token)
|
|
|
56 |
try:
|
57 |
result = audio_process(audio.file) # Replace with actual audio processing logic
|
58 |
return {"result": result}
|
main.py
CHANGED
@@ -8,20 +8,6 @@ from utils.rag import RAG
|
|
8 |
from faster_whisper import WhisperModel
|
9 |
|
10 |
|
11 |
-
# def dump_user_question(query):
|
12 |
-
# try:
|
13 |
-
# if os.path.exists:
|
14 |
-
# with open(r"data\question_data.pkl","rb") as f:
|
15 |
-
# que = pickle.load(f)
|
16 |
-
# else:
|
17 |
-
# que = []
|
18 |
-
# que.append(query)
|
19 |
-
# with open(r"data\question_data.pkl","wb") as f:
|
20 |
-
# que = pickle.dump(que,f)
|
21 |
-
# except:
|
22 |
-
# with open(r"data\question_data.pkl","wb") as f:
|
23 |
-
# pickle.dump([],f)
|
24 |
-
|
25 |
def process(user_query:str):
|
26 |
# dump_user_question(user_query)
|
27 |
user_embedding = GetEmbedding([user_query]).user_query_emb()
|
@@ -46,7 +32,7 @@ def process(user_query:str):
|
|
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)
|
@@ -62,6 +48,7 @@ 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)
|
67 |
# print(result)
|
|
|
8 |
from faster_whisper import WhisperModel
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def process(user_query:str):
|
12 |
# dump_user_question(user_query)
|
13 |
user_embedding = GetEmbedding([user_query]).user_query_emb()
|
|
|
32 |
|
33 |
def audio_process(audio):
|
34 |
try:
|
35 |
+
model = WhisperModel(model_size_or_path="medium.en")
|
36 |
segments, info = model.transcribe(audio)
|
37 |
transcription = " ".join([seg.text for seg in segments])
|
38 |
result = process(user_query=transcription)
|
|
|
48 |
res = audio_process(r"C:\Users\lalit\Documents\Sound recordings\who_is_lalit.m4a")
|
49 |
print(res)
|
50 |
# for _ in range(3):
|
51 |
+
|
52 |
# user = input("How can i help you :? \n")
|
53 |
# result = process(user)
|
54 |
# print(result)
|