Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from typing import List, Dict, Optional
|
| 5 |
+
|
| 6 |
+
GradientJResponse = Dict[str,str]
|
| 7 |
+
ChatHistory = List[Dict[str,str]]
|
| 8 |
+
|
| 9 |
+
def gradientj_api_call(
|
| 10 |
+
scene:str="",
|
| 11 |
+
chat_history:Optional[ChatHistory]=None
|
| 12 |
+
) -> GradientJResponse:
|
| 13 |
+
if chat_history is None:
|
| 14 |
+
chat_history = []
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
url = "https://gpt.gradientj.com/api/v0/deploy/inference"
|
| 18 |
+
headers = {
|
| 19 |
+
"Content-Type": "application/json",
|
| 20 |
+
"x-api-key": os.environ["YOUR_GJ_API_KEY"]
|
| 21 |
+
}
|
| 22 |
+
data = {
|
| 23 |
+
"model": os.environ["model_id"],
|
| 24 |
+
"params": {
|
| 25 |
+
"scene": scene
|
| 26 |
+
},
|
| 27 |
+
"chat_history": chat_history
|
| 28 |
+
}
|
| 29 |
+
response = requests.post(url, headers=headers, data=json.dumps(data))
|
| 30 |
+
|
| 31 |
+
if response.status_code == 200:
|
| 32 |
+
return response.text
|
| 33 |
+
else:
|
| 34 |
+
error = response.text
|
| 35 |
+
return error
|
| 36 |
+
|
| 37 |
+
demo = gr.Interface(
|
| 38 |
+
fn=gradientj_api_call,
|
| 39 |
+
inputs=["text"],
|
| 40 |
+
outputs=["text"],
|
| 41 |
+
examples=
|
| 42 |
+
[[
|
| 43 |
+
"""SCENE 20
|
| 44 |
+
EXT.ROAD WARANGAL
|
| 45 |
+
Highway mida car velthundi
|
| 46 |
+
Warangal board kanipistadi
|
| 47 |
+
SETHUMURTHY
|
| 48 |
+
(Voice)
|
| 49 |
+
Bajji ichina information tho
|
| 50 |
+
mundhuki vellalem.."""
|
| 51 |
+
]],
|
| 52 |
+
title="Tinglish (Telugu in Latin) to English Translation",
|
| 53 |
+
description="Description ah? Bokka?")
|
| 54 |
+
demo.launch()
|