hsienchen commited on
Commit
5f697ac
1 Parent(s): ed9051a

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -157
app.py DELETED
@@ -1,157 +0,0 @@
1
- import PIL.Image
2
- import gradio as gr
3
- import base64
4
- import time
5
- import os
6
- import google.generativeai as genai
7
-
8
- import pathlib
9
-
10
- txt_model = genai.GenerativeModel('gemini-pro')
11
- vis_model = genai.GenerativeModel('gemini-pro-vision')
12
-
13
- 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:
14
-
15
- # Sender and Subject #
16
- 1- Action 1 (no more than 20 words)
17
- 2- Action 2 (no more than 20 words)
18
- 3- Action 3 (no more than 20 words)
19
-
20
- For example:
21
- # From Richard regarding 'Shipping to Customer ABC' #
22
- 1- Pack Product A
23
- 2- Ship before 3:00 PM today
24
- 3- Notify Richard after shipment
25
- """
26
-
27
- txt_display_1 = 'content of email'
28
-
29
- import os
30
-
31
- GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
32
-
33
- genai.configure(api_key=GOOGLE_API_KEY)
34
-
35
- # Image to Base 64 Converter
36
- def image_to_base64(image_path):
37
- with open(image_path, 'rb') as img:
38
- encoded_string = base64.b64encode(img.read())
39
- return encoded_string.decode('utf-8')
40
-
41
- # Function that takes User Inputs and displays it on ChatUI
42
- def app2_query(history,txt,img):
43
- if not img:
44
- history += [(txt,None)]
45
- return history
46
- base64 = image_to_base64(img)
47
- data_url = f"data:image/jpeg;base64,{base64}"
48
- history += [(f"{txt} ![]({data_url})", None)]
49
- return history
50
-
51
- # Function that takes User Inputs, generates Response and displays on Chat UI
52
- def app2_response(history,text,img):
53
- if not img:
54
- response = txt_model.generate_content(text)
55
- history += [(None,response.text)]
56
- return history
57
-
58
- else:
59
- img = PIL.Image.open(img)
60
- response = vis_model.generate_content([text,img])
61
- history += [(None,response.text)]
62
- return history
63
-
64
- # Function that takes User Inputs and displays it on ChatUI
65
-
66
- def app3_query(history,img):
67
- if not img:
68
- history += [(txt_prompt_1,None)]
69
- return history
70
- base64 = image_to_base64(img)
71
- data_url = f"data:image/jpeg;base64,{base64}"
72
- history += [(f"![]({data_url})", None)]
73
- return history
74
-
75
-
76
- # Function that takes User Inputs, generates Response and displays on Chat UI
77
- def app3_response(history,img):
78
- if not img:
79
- response = txt_model.generate_content(txt_prompt_1)
80
- history += [(None,response.text)]
81
- return history
82
-
83
- else:
84
- img = PIL.Image.open(img)
85
- response = vis_model.generate_content([txt_prompt_1,img])
86
- history += [(None,response.text)]
87
- return history
88
-
89
-
90
- # Interface Code- Selector method
91
-
92
- def sentence_builder(animal, place):
93
- return f"""how many {animal}s from the {place} are shown in the picture?"""
94
-
95
- # gradio block
96
-
97
- with gr.Blocks(theme='snehilsanyal/scikit-learn') as app1:
98
- with gr.Column():
99
- outputbox = gr.Textbox(label="here are the plans...")
100
- image_box = gr.Image(type="filepath")
101
- chatbot = gr.Chatbot(
102
- scale = 2,
103
- height=750
104
- )
105
- btn = gr.Button("Make a Plan")
106
- clicked = btn.click(app3_query,
107
- [chatbot,image_box],
108
- chatbot
109
- ).then(app3_response,
110
- [chatbot],
111
- chatbot
112
- )
113
- gr.Markdown("""
114
- # Make a Plan #
115
-
116
- - screen capture (Win + shift + S)
117
- - click **Make a Plan** to upload
118
- - await LLM Bot (Gemini, in this case) response
119
- - receive THREE actionable items
120
-
121
-
122
- [demo](https://youtu.be/lJ4jIAEVRNY)
123
-
124
- """)
125
-
126
- with gr.Blocks(theme='snehilsanyal/scikit-learn') as app2:
127
- gr.Markdown("check the image...")
128
- with gr.Row():
129
- image_box = gr.Image(type="filepath")
130
-
131
- chatbot = gr.Chatbot(
132
- scale = 2,
133
- height=750
134
- )
135
- text_box = gr.Dropdown(
136
- ["what is in the image",
137
- "provide alternative title for the image",
138
- "how many parts can be seen in the picture?",
139
- "check ID and expiration date"],
140
- label="Select--",
141
- info="ask Bot"
142
- )
143
-
144
- btn = gr.Button("Submit")
145
- clicked = btn.click(app2_query,
146
- [chatbot,text_box,image_box],
147
- chatbot
148
- ).then(app2_response,
149
- [chatbot,text_box],
150
- chatbot
151
- )
152
- with gr.Blocks(theme='snehilsanyal/scikit-learn') as demo:
153
- gr.Markdown("## Workflow Bot ##")
154
- gr.TabbedInterface([app1, app2], ["Make a Plan!", "Check This!"])
155
-
156
- demo.queue()
157
- demo.launch()