|
from fastapi import FastAPI, HTTPException |
|
from pydantic import BaseModel |
|
from deep_translator import GoogleTranslator |
|
from fastapi.responses import JSONResponse |
|
from main import process |
|
|
|
app = FastAPI() |
|
|
|
|
|
@app.get("/") |
|
async def home(): |
|
return {"message": "Welcome to my FastAPI API on Hugging Face Spaces!"} |
|
|
|
|
|
@app.get("/translate") |
|
async def translate(text: str = ""): |
|
if not text: |
|
raise HTTPException(status_code=400, detail="No text provided") |
|
|
|
|
|
translator = GoogleTranslator(source="auto", target="mr") |
|
result = translator.translate(text) |
|
|
|
return {"result": result} |
|
|
|
@app.get("/chatbot") |
|
async def chatbot(text: str = ""): |
|
if not text: |
|
raise HTTPException(status_code=400, detail="No text provided") |
|
|
|
result = process(query=text) |
|
return {"result": result} |
|
|
|
|