import requests import json import os from typing import List, Dict, Optional import gradio as gr GradientJResponse = Dict[str,str] ChatHistory = List[Dict[str,str]] def gradientj_api_call( scene:str="", chat_history:Optional[ChatHistory]=None ) -> GradientJResponse: if chat_history is None: chat_history = [] url = "https://gpt.gradientj.com/api/v0/deploy/inference" headers = { "Content-Type": "application/json", "x-api-key": os.environ["YOUR_GJ_API_KEY"] } data = { "model": os.environ["model_id"], "params": { "scene": scene }, "chat_history": chat_history } response = requests.post(url, headers=headers, data=json.dumps(data)) if response.status_code == 200: return response.json()['result'] else: error = response.text return error demo = gr.Interface( fn=gradientj_api_call, inputs=["text"], outputs=["text"], examples= [[ """SCENE 20 EXT.ROAD WARANGAL Highway mida car velthundi Warangal board kanipistadi SETHUMURTHY (Voice) Bajji ichina information tho mundhuki vellalem..""" ]], title="Tinglish (Telugu in Latin) to English Translation", description="Description ah? Bokka?") demo.launch()