rishabh-zuma commited on
Commit
17a6d8e
·
1 Parent(s): 87c7a4c

Upload folder using huggingface_hub

Browse files
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .env
2
+ .idea
3
+ env
4
+ .log
README.md CHANGED
@@ -1,12 +1,7 @@
1
  ---
2
  title: ImageSense
3
- emoji: 🏆
4
- colorFrom: pink
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.39.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: ImageSense
3
+ app_file: image_caption/gradio_interface.py
 
 
4
  sdk: gradio
5
  sdk_version: 3.39.0
 
 
6
  ---
7
+ # sales-demo
 
image_caption/__init__.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ """__init__.py: """
4
+
5
+ __author__ = "Rishabh Gupta"
6
+ __copyright__ = "Copyright 2023, Zuma"
7
+ __created_date__ = "04-08-2023"
8
+
9
+ if __name__ == '__main__':
10
+ pass
image_caption/get_caption.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ """get_caption.py: """
4
+
5
+ __author__ = "Rishabh Gupta"
6
+ __copyright__ = "Copyright 2023, Zuma"
7
+ __created_date__ = "04-08-2023"
8
+
9
+
10
+ import os
11
+ import json
12
+ import requests
13
+ import base64
14
+ from io import BytesIO
15
+
16
+ def get_image_caption(img_obj, prompt=None):
17
+ """
18
+
19
+ Args:
20
+ img_obj: Base 64 image object
21
+ prompt: Prompt to be used for captioning
22
+
23
+ Returns:
24
+ Captions for the image
25
+ """
26
+ # print("Image Obj", img_obj)
27
+
28
+
29
+ buffered = BytesIO()
30
+ img_obj.save(buffered, format="JPEG")
31
+ img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
32
+ url = os.environ.get("IMAGE_CAPTION_ENDPOINT")
33
+ auth_token = os.environ.get("IMAGE_CAPTION_AUTH_TOKEN")
34
+ # print("img_str", img_str)
35
+ payload = json.dumps({
36
+ "inputs": img_str,
37
+ "prompt": None # Prompts are disabled as accuracy is not very good or not experimented enough.
38
+ })
39
+ headers = {
40
+ 'Authorization': auth_token,
41
+ 'Content-Type': 'application/json'
42
+ }
43
+ response = requests.request("POST", url, headers=headers, data=payload)
44
+ print("Response Status Code = ", response.status_code)
45
+ print("Response = ", response.text)
46
+ if response.status_code == 200:
47
+ caption = json.loads(response.text)["captions"]
48
+ print(f"Caption = {caption}")
49
+ return caption
50
+ else:
51
+ return "Error in generating the caption!"
52
+
53
+
54
+ if __name__ == '__main__':
55
+ with open("/Users/rishabh/Downloads/5dbadb934042f1.16205085439.jpg", "rb") as image_file:
56
+ encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
57
+ print(get_image_caption(encoded_string))
image_caption/gradio_interface.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ """gradio_interface.py: """
4
+
5
+ __author__ = "Rishabh Gupta"
6
+ __copyright__ = "Copyright 2023, Zuma"
7
+ __created_date__ = "04-08-2023"
8
+
9
+ import gradio as gr
10
+ from image_caption import get_caption
11
+
12
+
13
+ gr.Interface(fn=get_caption.get_image_caption,
14
+ inputs=gr.Image(type="pil"),
15
+ outputs=gr.Label(num_top_classes=3),
16
+ examples=["bathroom.jpg", "image_caption/examples/livingRoom.jpg"]).launch()
17
+
18
+ if __name__ == '__main__':
19
+ pass
requirementx.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio==-3.39.0