Ufoptg commited on
Commit
9fb903f
1 Parent(s): 2d2cef5

Update main.py

Browse files

dalle3xl trial add

Files changed (1) hide show
  1. main.py +37 -0
main.py CHANGED
@@ -71,11 +71,14 @@ from models import *
71
 
72
  logging.basicConfig(level=logging.ERROR)
73
 
 
 
74
  # I DON'T KNOW LIKE THIS HACKER
75
  load_dotenv()
76
  SOURCE_UNSPLASH_URL = os.environ["SOURCE_UNSPLASH_URL"]
77
  SOURCE_OCR_URL = os.environ["SOURCE_OCR_URL"]
78
  SOURCE_ALPHA_URL = os.environ["SOURCE_ALPHA_URL"]
 
79
  SOURCE_WAIFU_URL = "https://api.waifu.pics"
80
  SOURCE_TIKTOK_WTF_URL = os.environ["SOURCE_TIKTOK_WTF_URL"]
81
  SOURCE_TIKTOK_TECH_URL = os.environ["SOURCE_TIKTOK_TECH_URL"]
@@ -109,6 +112,12 @@ app = FastAPI(
109
  docs_url="/"
110
  )
111
 
 
 
 
 
 
 
112
  def validate_api_key(api_key: str = Header(...)):
113
  USERS_API_KEYS = db.get_all_api_keys()
114
  if api_key not in USERS_API_KEYS:
@@ -243,6 +252,34 @@ def v1beta3_google_ai(
243
  except:
244
  return {"status": "false", "message": "Error response."}
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  @app.get("/ryuzaki/unsplash")
247
  async def get_image_unsplash(query: str, size: str="500x500"):
248
  url = SOURCE_UNSPLASH_URL
 
71
 
72
  logging.basicConfig(level=logging.ERROR)
73
 
74
+ #MONGO_URL = os.environ["MONGO_URL"]
75
+
76
  # I DON'T KNOW LIKE THIS HACKER
77
  load_dotenv()
78
  SOURCE_UNSPLASH_URL = os.environ["SOURCE_UNSPLASH_URL"]
79
  SOURCE_OCR_URL = os.environ["SOURCE_OCR_URL"]
80
  SOURCE_ALPHA_URL = os.environ["SOURCE_ALPHA_URL"]
81
+ SOURCE_DALLE3XL_URL = os.environ["SOURCE_DALLE3XL_URL"]
82
  SOURCE_WAIFU_URL = "https://api.waifu.pics"
83
  SOURCE_TIKTOK_WTF_URL = os.environ["SOURCE_TIKTOK_WTF_URL"]
84
  SOURCE_TIKTOK_TECH_URL = os.environ["SOURCE_TIKTOK_TECH_URL"]
 
112
  docs_url="/"
113
  )
114
 
115
+ contact_support = """
116
+ We are aware that this service is currently offline. This seems to be caused by the API
117
+ We are investigating and doing our best to get things back online as soon as possible. Thank you for your patience
118
+ Contact Support @soulofsukuna
119
+ """
120
+
121
  def validate_api_key(api_key: str = Header(...)):
122
  USERS_API_KEYS = db.get_all_api_keys()
123
  if api_key not in USERS_API_KEYS:
 
252
  except:
253
  return {"status": "false", "message": "Error response."}
254
 
255
+ @app.post("/UFoP/dalle3xl")
256
+ def dalle_3xl(
257
+ item: Dalle3XL,
258
+ api_key: None = Depends(validate_api_key)
259
+ ):
260
+ API_URL = SOURCE_DALLE3XL_URL
261
+ try:
262
+ payload = {"inputs": item.query}
263
+ headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
264
+ response = requests.post(API_URL, headers=headers, json=payload)
265
+ response.raise_for_status()
266
+ except requests.exceptions.RequestException:
267
+ raise HTTPException(
268
+ status_code=500,
269
+ detail=CustomErrorResponseModel(detail=[{}])
270
+ )
271
+ try:
272
+ encoded_string = base64.b64encode(response.content).decode("utf-8")
273
+ except Exception:
274
+ raise HTTPException(
275
+ status_code=500,
276
+ detail=CustomErrorResponseModel(detail=[{}])
277
+ )
278
+ if encoded_string:
279
+ return SuccessResponse(status="True", sukuna={"data": encoded_string})
280
+ else:
281
+ return SuccessResponse(status="False", sukuna={"data": contact_support})
282
+
283
  @app.get("/ryuzaki/unsplash")
284
  async def get_image_unsplash(query: str, size: str="500x500"):
285
  url = SOURCE_UNSPLASH_URL