File size: 7,119 Bytes
930f89e f22cb33 1fe660b f22cb33 8c29b70 f22cb33 ba9c0ad 3c58186 789b2ec 3c58186 b3c6c9d 789b2ec b3c6c9d 5e1b277 789b2ec 3c58186 5ae7420 b3c6c9d 5e1b277 0354a2a 5ae7420 3c58186 789b2ec b3c6c9d 3c58186 d1bf604 3c58186 f22cb33 b34adbe f22cb33 60361bd f22cb33 930f89e f22cb33 930f89e f22cb33 930f89e 1fe660b 3c58186 a34f4ad b34adbe 1fe660b b34adbe 1fe660b db85d2b bd53307 f22cb33 98556ba b8f63e5 2ad436c 8e025f4 2ad436c 27dba5b b8f63e5 3c9a223 60361bd 98556ba 1fe660b 60361bd f22cb33 3a29aff f22cb33 3a29aff f22cb33 f5027f2 f22cb33 c13947e 65f8bb5 128b53d 2ad436c 8e025f4 2ad436c 27dba5b 3c9a223 128b53d 3c58186 128b53d f22cb33 128b53d 3a29aff 128b53d 3a29aff 128b53d 3a29aff 128b53d f22cb33 2d3ae4b 9baabee f5027f2 9baabee 29fc1b8 9baabee 29fc1b8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# refer to repo https://github.com/gradio-app/gradio/blob/main/demo/chatbot_multimodal/run.ipynb for enhancement
import PIL.Image
import gradio as gr
import base64
import time
import os
import google.generativeai as genai
import requests
import pathlib
txt_model = genai.GenerativeModel('gemini-pro')
vis_model = genai.GenerativeModel('gemini-pro-vision')
txt_prompt_1 = """The image contains the contents of a letter. I'd like to follow the request mentioned in the letter. Please provide 3 actionable items to assist me. When responding, use the following format:
# Sender and Subject #
1- Action 1 (no more than 20 words)
2- Action 2 (no more than 20 words)
3- Action 3 (no more than 20 words)
For example:
# From Richard regarding 'Shipping to Customer ABC' #
1- Pack Product A
2- Ship before 3:00 PM today
3- Notify Richard after shipment
"""
txt_display_1 = 'content of the letter: '
txt_prompt_2 = """First, to determine if the image is related to inventory and contains necessary information, consider the base reference of "a valid inventory table should be a table format with columns for Item ID, Quantity, Minimum, and Contact Phone."
If the image does not align with this base reference, please respond accordingly with "not applicable, as the image appears not related or lacks necessary information."
If the image aligns with this base reference, proceed with the following steps to generate a response:
Check the Quantity against the respective Minimum for each row. If the Quantity is less than the Minimum, then the respective Item ID is in a shortage state, and the shortage is defined as the negative value of Quantity - Minimum. Provide a list of all items in shortage in the following format:
** SOS shortage (MM/DD/YYYY) **
Item ID, Shortage (Quantity - Minimum), Contact Phone
For example, considering the below Table,
| Item ID | Quantity | Minimum | Contact Phone |
| ----------- | ----------- |
| #01 | 30 | 50 | 1234
| #02 | 40 | 20 | 3456
| #03 | 5 | 10 | 4567
the respective response should be as follow:
** SOS shortage **
#01, -20 (30 - 50), 1234
#03, -5 (5 - 10), 4567
When rendering the response, please ensure ALL items in shortage state are on the list. Also, be aware that there may also be NO item in shortage state.
"""
txt_display_2 = '--- '
import os
GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
genai.configure(api_key=GOOGLE_API_KEY)
SMS_URL =os.getenv('SMS_URL')
SMS_TOK =os.getenv('SMS_TOK')
sms_text ="..."
# Image to Base 64 Converter
def image_to_base64(image_path):
with open(image_path, 'rb') as img:
encoded_string = base64.b64encode(img.read())
return encoded_string.decode('utf-8')
# Function that takes User Inputs, generates Response and displays on Chat UI
def app1_response(img):
if not img:
response = txt_model.generate_content(txt_prompt_1)
return response
else:
img = PIL.Image.open(img)
response = vis_model.generate_content([txt_prompt_1,img])
return response.text
def app2_response(img):
if not img:
response = txt_model.generate_content(txt_prompt_2)
return response
else:
img = PIL.Image.open(img)
response = vis_model.generate_content([txt_prompt_2,img])
return response.text
# SMS service ends in March 2024, to restore service @Sinch Simple Text
def send_SMS(resp_text):
url = SMS_URL
headers = {
"Authorization": SMS_TOK,
"Content-Type": "application/json"
}
data = {
"from": "12085686834",
"to": ["18587331029"],
"body": resp_text
}
# response = requests.post(url, json=data, headers=headers)
# return response.text
return "....."
# gradio block
with gr.Blocks() as app1:
with gr.Column():
gr.Markdown("## π₯· to Samuraize ##")
gr.Markdown("```for email β and/or assigment descriptions β¦, paste screenshot here...```")
image_box = gr.Image(label="β email screen", type="filepath")
btn1 = gr.Button("Generate To-Dos β")
out1 = gr.Textbox(label="here are the actionables...")
btn2 = gr.Button("(disabled)send to Mobile βοΈ")
out2 = gr.Textbox(label="(disabled) no message been sent, this is just a mockup confirmation...")
btn1.click(fn=app1_response, inputs=[image_box], outputs=out1)
btn2.click(fn=send_SMS, inputs=out1, outputs=out2)
gr.Markdown("""
# π₯· Summerize eMail & Make a Plan #
- screen capture (Win + shift + S)
- click β to upload
- await LLM Bot (Gemini, in this case) response
- receive THREE actionable items
[demo video](https://youtu.be/lJ4jIAEVRNY)
""")
examples=[
os.path.join(os.path.dirname(__file__), "images/missionemail.png"),
],
with gr.Blocks() as app2:
with gr.Column():
gr.Markdown("## 𦫠Stock-Out Squirrel ##")
gr.Markdown("```Win+Screenshot, paste ERP Inv β¨ screenshot here...```")
image_box = gr.Image(label="β ERP screen",type="filepath")
btn1 = gr.Button("Check ROQ β")
out1 = gr.Textbox(label="here is the watch list π...")
btn2 = gr.Button("(disabled)send out reminders βοΈ")
out2 = gr.Textbox(label="response or feed back?")
btn1.click(fn=app2_response, inputs=[image_box], outputs=out1)
btn2.click(fn=send_SMS, inputs=out1, outputs=out2)
gr.Markdown("""
# 𦫠Check Inventory ROQ #
(contains bugs, more works needed)
- screen capture (Win + shift + S)
- click β to upload
- await LLM Bot (Gemini, in this case) response
- send βοΈ to related parties
""")
gr.Markdown("""
- [x] Sample Inventory Table
- [X] Screen Capture and Paste
""")
gr.Markdown("""
| Item ID | Quantity | Minimum|Contact Phone|
|--|--|--|--|
| #01 | 50 | 20 | 1234|
| #02 | 40 | 50 | 3456|
| #03 | 80 | 20 | 1234|
""")
with gr.Blocks() as app3:
with gr.Column():
gr.Markdown("## π Route Planning Rabbit ##")
gr.Markdown("```Win+Screenshot, paste ERP Inv β¨ screenshot here...```")
image_box = gr.Image(label="β Pick list",type="filepath")
btn1 = gr.Button("Generate a Route Plan β")
out1 = gr.Textbox(label="here is the watch list π...")
btn2 = gr.Button("send to Mobile (disabled) βοΈ")
out2 = gr.Textbox(label="no message been sent, this is just a mockup confirmation...")
btn1.click(fn=app2_response, inputs=[image_box], outputs=out1)
btn2.click(fn=send_SMS, inputs=out1, outputs=out2)
gr.Markdown("""
# π Route Planning #
(concept prototype)
- screen capture (Win + shift + S)
- click β to upload
- await LLM Bot (Gemini, in this case) response
- send βοΈ to related parties
""")
with gr.Blocks() as demo:
gr.Markdown("## To-Do Samuraizer π₯· + Stock-Out Squirrel𦫠+ Routing π ##")
gr.TabbedInterface([app1, app2, app3], ["β To-Do", "β SOS", "β Picking Routes"])
demo.queue()
demo.launch() |