Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,9 @@ from fastapi.templating import Jinja2Templates
|
|
15 |
from huggingface_hub import InferenceClient
|
16 |
import json
|
17 |
import re
|
18 |
-
from
|
|
|
|
|
19 |
|
20 |
# Define Pydantic model for incoming request body
|
21 |
class MessageRequest(BaseModel):
|
@@ -31,7 +33,7 @@ llm_client = InferenceClient(
|
|
31 |
os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
|
32 |
|
33 |
app = FastAPI()
|
34 |
-
|
35 |
@app.middleware("http")
|
36 |
async def add_security_headers(request: Request, call_next):
|
37 |
response = await call_next(request)
|
@@ -161,7 +163,9 @@ async def chat(request: MessageRequest):
|
|
161 |
response = handle_query(message) # Process the message
|
162 |
response1 = response
|
163 |
try:
|
164 |
-
|
|
|
|
|
165 |
print(response1)
|
166 |
except Exception as e:
|
167 |
# Handle translation errors
|
|
|
15 |
from huggingface_hub import InferenceClient
|
16 |
import json
|
17 |
import re
|
18 |
+
from deep_translator import GoogleTranslator
|
19 |
+
|
20 |
+
|
21 |
|
22 |
# Define Pydantic model for incoming request body
|
23 |
class MessageRequest(BaseModel):
|
|
|
33 |
os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
|
34 |
|
35 |
app = FastAPI()
|
36 |
+
|
37 |
@app.middleware("http")
|
38 |
async def add_security_headers(request: Request, call_next):
|
39 |
response = await call_next(request)
|
|
|
163 |
response = handle_query(message) # Process the message
|
164 |
response1 = response
|
165 |
try:
|
166 |
+
translator = GoogleTranslator(source='en', target=language_code) # Translate to Tamil
|
167 |
+
response1 = translator.translate(response)
|
168 |
+
#response1 = translator.translate(response, dest=language_code).text
|
169 |
print(response1)
|
170 |
except Exception as e:
|
171 |
# Handle translation errors
|