fesvhtr commited on
Commit
3250465
1 Parent(s): 1f30fbc

Upload app.ipynb

Browse files
Files changed (1) hide show
  1. app.ipynb +25 -21
app.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 14,
6
  "metadata": {
7
  "collapsed": true
8
  },
@@ -124,6 +124,9 @@
124
  " return conversation,[history,conversation]\n",
125
  "\n",
126
  "def run_chatbot_with_img(input_img,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state=[]):\n",
 
 
 
127
  " history, conversation = gr_state[0],gr_state[1]\n",
128
  "\n",
129
  " # TODO: save img and show in conversation\n",
@@ -135,6 +138,7 @@
135
  " input = 'I have given you a photo about '+ img_cls + ', and tell me its definition.'\n",
136
  " output = chat_with_GPT(input,history,max_tokens,temperature,frequency_penalty,presence_penalty)\n",
137
  "\n",
 
138
  " input_mask = 'Upload image'\n",
139
  " # conversation save chatbox content\n",
140
  " conversation.append((input_mask,output))\n",
@@ -144,7 +148,7 @@
144
  " # chatbox gr_state\n",
145
  " return conversation , [history,conversation]\n",
146
  "\n",
147
- "def save_img(image):\n",
148
  "\n",
149
  " filename = next(tempfile._get_candidate_names()) + '.png'\n",
150
  " print(filename)\n",
@@ -172,7 +176,7 @@
172
  },
173
  {
174
  "cell_type": "code",
175
- "execution_count": 16,
176
  "outputs": [
177
  {
178
  "name": "stderr",
@@ -181,9 +185,7 @@
181
  "D:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\gradio\\inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
182
  " warnings.warn(\n",
183
  "D:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
184
- " warnings.warn(value)\n",
185
- "D:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Number, please remove them: {'minimum': 500, 'maximum': 2000}\n",
186
- " warnings.warn(\n"
187
  ]
188
  },
189
  {
@@ -207,20 +209,10 @@
207
  "name": "stdout",
208
  "output_type": "stream",
209
  "text": [
210
- "college\n",
211
- "0.3043000400066376\n",
212
- "doorplate\n",
213
- "0.7027668356895447\n",
214
- "Keyboard interruption in main thread... closing server.\n"
215
  ]
216
- },
217
- {
218
- "data": {
219
- "text/plain": ""
220
- },
221
- "execution_count": 16,
222
- "metadata": {},
223
- "output_type": "execute_result"
224
  }
225
  ],
226
  "source": [
@@ -252,7 +244,7 @@
252
  " image_btn = gr.UploadButton(\"Upload Image\", file_types=[\"image\"])\n",
253
  " with gr.Column(scale=0.3, min_width=400):\n",
254
  " max_tokens = gr.Number(\n",
255
- " minimum=500, maximum=2000, value=1000, precision=1, interactive=True, label=\"Maximum length of generated text\")\n",
256
  " temperature = gr.Slider(\n",
257
  " minimum=0.0, maximum=1.0, value=0.0, interactive=True, label=\"Diversity of generated text\")\n",
258
  " frequency_penalty = gr.Slider(minimum=-2.0, maximum=2.0, value=0.5,\n",
@@ -271,10 +263,22 @@
271
  " submit_btn.click(lambda: \"\", None, text_input)\n",
272
  " reset_btn.click(fn=reset,inputs=[],outputs=[chatbot,gr_state])\n",
273
  " submit_btn_img.click(run_chatbot_with_img, [image,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state], [chatbot,gr_state])\n",
274
- " # image_btn.upload(run_chatbot_with_img, [image,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state], [chatbot,gr_state])\n",
275
  "\n",
276
  "demo.launch(debug = True)"
277
  ],
 
 
 
 
 
 
 
 
 
 
 
 
278
  "metadata": {
279
  "collapsed": false
280
  }
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 16,
6
  "metadata": {
7
  "collapsed": true
8
  },
 
124
  " return conversation,[history,conversation]\n",
125
  "\n",
126
  "def run_chatbot_with_img(input_img,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state=[]):\n",
127
+ " print(type(input_img))\n",
128
+ " # input_image = Image.open(input_img.name).convert('RGB')\n",
129
+ " # input_image.save(input_image.name)\n",
130
  " history, conversation = gr_state[0],gr_state[1]\n",
131
  "\n",
132
  " # TODO: save img and show in conversation\n",
 
138
  " input = 'I have given you a photo about '+ img_cls + ', and tell me its definition.'\n",
139
  " output = chat_with_GPT(input,history,max_tokens,temperature,frequency_penalty,presence_penalty)\n",
140
  "\n",
141
+ " # input_mask = [(f'<img src=\"/file={input_img.name}\" style=\"display: inline-block;\">', \"\")]\n",
142
  " input_mask = 'Upload image'\n",
143
  " # conversation save chatbox content\n",
144
  " conversation.append((input_mask,output))\n",
 
148
  " # chatbox gr_state\n",
149
  " return conversation , [history,conversation]\n",
150
  "\n",
151
+ "def save_img(image: Image.Image):\n",
152
  "\n",
153
  " filename = next(tempfile._get_candidate_names()) + '.png'\n",
154
  " print(filename)\n",
 
176
  },
177
  {
178
  "cell_type": "code",
179
+ "execution_count": null,
180
  "outputs": [
181
  {
182
  "name": "stderr",
 
185
  "D:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\gradio\\inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
186
  " warnings.warn(\n",
187
  "D:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
188
+ " warnings.warn(value)\n"
 
 
189
  ]
190
  },
191
  {
 
209
  "name": "stdout",
210
  "output_type": "stream",
211
  "text": [
212
+ "<class 'numpy.ndarray'>\n",
213
+ "panda\n",
214
+ "0.3023892641067505\n"
 
 
215
  ]
 
 
 
 
 
 
 
 
216
  }
217
  ],
218
  "source": [
 
244
  " image_btn = gr.UploadButton(\"Upload Image\", file_types=[\"image\"])\n",
245
  " with gr.Column(scale=0.3, min_width=400):\n",
246
  " max_tokens = gr.Number(\n",
247
+ " value=1000, precision=1, interactive=True, label=\"Maximum length of generated text\")\n",
248
  " temperature = gr.Slider(\n",
249
  " minimum=0.0, maximum=1.0, value=0.0, interactive=True, label=\"Diversity of generated text\")\n",
250
  " frequency_penalty = gr.Slider(minimum=-2.0, maximum=2.0, value=0.5,\n",
 
263
  " submit_btn.click(lambda: \"\", None, text_input)\n",
264
  " reset_btn.click(fn=reset,inputs=[],outputs=[chatbot,gr_state])\n",
265
  " submit_btn_img.click(run_chatbot_with_img, [image,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state], [chatbot,gr_state])\n",
266
+ " image_btn.upload(run_chatbot_with_img, [image_btn,max_tokens,temperature,frequency_penalty,presence_penalty,gr_state], [chatbot,gr_state])\n",
267
  "\n",
268
  "demo.launch(debug = True)"
269
  ],
270
+ "metadata": {
271
+ "collapsed": false,
272
+ "pycharm": {
273
+ "is_executing": true
274
+ }
275
+ }
276
+ },
277
+ {
278
+ "cell_type": "code",
279
+ "execution_count": null,
280
+ "outputs": [],
281
+ "source": [],
282
  "metadata": {
283
  "collapsed": false
284
  }