Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
update introduction
Browse files
app.py
CHANGED
@@ -5,9 +5,6 @@ import os
|
|
5 |
import json
|
6 |
import requests
|
7 |
import time
|
8 |
-
from PIL import Image
|
9 |
-
import datetime
|
10 |
-
|
11 |
from concurrent.futures import ThreadPoolExecutor
|
12 |
from utils import is_chinese, process_image_without_resize, parse_response, templates_agent_cogagent, template_grounding_cogvlm, postprocess_text
|
13 |
|
@@ -31,41 +28,6 @@ def make_request(URL, headers, data):
|
|
31 |
response = requests.request("POST", URL, headers=headers, data=data, timeout=(60, 100))
|
32 |
return response.json()
|
33 |
|
34 |
-
def report_fn(image_prompt, result_previous, report=False, base_dir='/home/wangyan/data/badcases'):
|
35 |
-
if not report:
|
36 |
-
return "Report failed! Checking Report when you want to report a bad case!"
|
37 |
-
|
38 |
-
os.makedirs(base_dir, exist_ok=True)
|
39 |
-
date_dir = datetime.datetime.now().strftime('%Y%m%d')
|
40 |
-
new_dir = os.path.join(base_dir, date_dir)
|
41 |
-
os.makedirs(new_dir, exist_ok=True)
|
42 |
-
conv_path = os.path.join(base_dir, f'cases_report_{date_dir}.jsonl')
|
43 |
-
|
44 |
-
result_text = [(ele[0], ele[1]) for ele in result_previous]
|
45 |
-
for i in range(len(result_text)-1, -1, -1):
|
46 |
-
if result_text[i][0] == "" or result_text[i][0] == None:
|
47 |
-
del result_text[i]
|
48 |
-
|
49 |
-
if image_prompt and len(result_text) > 0:
|
50 |
-
image = Image.open(image_prompt)
|
51 |
-
timestamp = time.time()
|
52 |
-
file_ext = os.path.splitext(image_prompt)[1]
|
53 |
-
filename = os.path.join(new_dir, f"{timestamp}{file_ext}")
|
54 |
-
image.save(filename)
|
55 |
-
|
56 |
-
conv_data = {
|
57 |
-
'id': str(int(time.time())),
|
58 |
-
'history': [filename, *[i for c in result_text for i in c]]
|
59 |
-
}
|
60 |
-
|
61 |
-
mode = 'a' if os.path.isfile(conv_path) else 'w'
|
62 |
-
with open(conv_path, mode) as f:
|
63 |
-
f.write(json.dumps(conv_data, ensure_ascii=False)+"\n")
|
64 |
-
return "Submit success!"
|
65 |
-
return "Submit failed!"
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
def post(
|
70 |
input_text,
|
71 |
temperature,
|
@@ -218,10 +180,6 @@ def main():
|
|
218 |
with gr.Column(scale=5.5):
|
219 |
result_text = gr.components.Chatbot(label='Multi-round conversation History', value=[("", "Hi, What do you want to know about this image?")], height=550)
|
220 |
hidden_image_hash = gr.Textbox(visible=False)
|
221 |
-
with gr.Row():
|
222 |
-
bad_case_button = gr.Button('Report bad case')
|
223 |
-
report = gr.Checkbox(label='Report')
|
224 |
-
report_text = gr.Textbox(value='', interactive=False, show_label=False)
|
225 |
|
226 |
gr_examples = gr.Examples(examples=[[example["text"], example["image"], example["grounding"], example["cogagent"]] for example in examples],
|
227 |
inputs=[input_text, image_prompt, grounding, cogagent],
|
@@ -238,7 +196,6 @@ def main():
|
|
238 |
clear_button.click(fn=clear_fn, inputs=clear_button, outputs=[input_text, result_text, image_prompt])
|
239 |
image_prompt.upload(fn=clear_fn2, inputs=clear_button, outputs=[result_text])
|
240 |
image_prompt.clear(fn=clear_fn2, inputs=clear_button, outputs=[result_text])
|
241 |
-
bad_case_button.click(fn=report_fn, inputs=[image_prompt, result_text, report], outputs=[report_text])
|
242 |
|
243 |
print(gr.__version__)
|
244 |
|
|
|
5 |
import json
|
6 |
import requests
|
7 |
import time
|
|
|
|
|
|
|
8 |
from concurrent.futures import ThreadPoolExecutor
|
9 |
from utils import is_chinese, process_image_without_resize, parse_response, templates_agent_cogagent, template_grounding_cogvlm, postprocess_text
|
10 |
|
|
|
28 |
response = requests.request("POST", URL, headers=headers, data=data, timeout=(60, 100))
|
29 |
return response.json()
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def post(
|
32 |
input_text,
|
33 |
temperature,
|
|
|
180 |
with gr.Column(scale=5.5):
|
181 |
result_text = gr.components.Chatbot(label='Multi-round conversation History', value=[("", "Hi, What do you want to know about this image?")], height=550)
|
182 |
hidden_image_hash = gr.Textbox(visible=False)
|
|
|
|
|
|
|
|
|
183 |
|
184 |
gr_examples = gr.Examples(examples=[[example["text"], example["image"], example["grounding"], example["cogagent"]] for example in examples],
|
185 |
inputs=[input_text, image_prompt, grounding, cogagent],
|
|
|
196 |
clear_button.click(fn=clear_fn, inputs=clear_button, outputs=[input_text, result_text, image_prompt])
|
197 |
image_prompt.upload(fn=clear_fn2, inputs=clear_button, outputs=[result_text])
|
198 |
image_prompt.clear(fn=clear_fn2, inputs=clear_button, outputs=[result_text])
|
|
|
199 |
|
200 |
print(gr.__version__)
|
201 |
|