Ashhar commited on
Commit
36bcbee
·
1 Parent(s): e8511c9

image serving from cloudinary

Browse files
Files changed (3) hide show
  1. app.py +4 -0
  2. helpers/imageCdn.py +22 -0
  3. requirements.txt +2 -0
app.py CHANGED
@@ -16,10 +16,12 @@ import utils as U
16
  from helpers.auth import runWithAuth
17
  from helpers.sidebar import showSidebar
18
  from helpers.activities import saveLatestActivity
 
19
 
20
  from dotenv import load_dotenv
21
  load_dotenv()
22
 
 
23
  ModelType = Literal["GPT4", "CLAUDE", "LLAMA"]
24
  ModelConfig = TypedDict("ModelConfig", {
25
  "client": OpenAI | Groq | anthropic.Anthropic,
@@ -465,6 +467,8 @@ def mainApp():
465
 
466
  imageContainer = st.empty()
467
  imagePath = __paintImageIfApplicable(imageContainer, prompt, response)
 
 
468
 
469
  st.session_state.chatHistory.append({
470
  "role": "assistant",
 
16
  from helpers.auth import runWithAuth
17
  from helpers.sidebar import showSidebar
18
  from helpers.activities import saveLatestActivity
19
+ from helpers.imageCdn import getCdnUrl
20
 
21
  from dotenv import load_dotenv
22
  load_dotenv()
23
 
24
+
25
  ModelType = Literal["GPT4", "CLAUDE", "LLAMA"]
26
  ModelConfig = TypedDict("ModelConfig", {
27
  "client": OpenAI | Groq | anthropic.Anthropic,
 
467
 
468
  imageContainer = st.empty()
469
  imagePath = __paintImageIfApplicable(imageContainer, prompt, response)
470
+ if imagePath:
471
+ imagePath = getCdnUrl(imagePath)
472
 
473
  st.session_state.chatHistory.append({
474
  "role": "assistant",
helpers/imageCdn.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cloudinary
2
+ from cloudinary import CloudinaryImage
3
+ import cloudinary.uploader
4
+ import cloudinary.api
5
+ import utils as U
6
+
7
+ config = cloudinary.config(secure=True)
8
+
9
+
10
+ def __getImageId(imagePath: str):
11
+ imagePath = imagePath.replace('\\', '/')
12
+ parts = imagePath.split('/')
13
+ return parts[-2]
14
+
15
+
16
+ def getCdnUrl(imagePath: str) -> str:
17
+ imageId = __getImageId(imagePath)
18
+ cloudinary.uploader.upload(imagePath, public_id=imageId, unique_filename=False, overwrite=True)
19
+ U.pprint(f"Image uploaded to CDN: {imageId}")
20
+ srcURL = CloudinaryImage(imageId).build_url()
21
+ U.pprint(f"Image CDN URL: {srcURL}")
22
+ return srcURL
requirements.txt CHANGED
@@ -6,3 +6,5 @@ gradio_client
6
  anthropic
7
  supabase
8
  descope
 
 
 
6
  anthropic
7
  supabase
8
  descope
9
+ cloudinary
10
+