GiantPandas commited on
Commit
ffed71d
·
verified ·
1 Parent(s): 9c9c32c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -70
app.py CHANGED
@@ -2,33 +2,19 @@ import gradio as gr
2
  import time
3
  import os
4
  import sys
 
5
  import json
6
  import base64
7
  import tqdm
8
  import base64
9
  from datetime import datetime
10
  import subprocess
11
- import time
12
- from http import HTTPStatus
13
- from urllib3.exceptions import HTTPError
14
  from pathlib import Path
15
  import numpy as np
16
  from PIL import Image
17
- import os
18
- import numpy as np
19
- from urllib3.exceptions import HTTPError
20
-
21
  from argparse import ArgumentParser
22
- from pathlib import Path
23
-
24
- import copy
25
- import gradio as gr
26
- import os
27
- import re
28
- import secrets
29
  import tempfile
30
- import requests
31
- from http import HTTPStatus
32
 
33
 
34
  # Function to encode the image
@@ -60,58 +46,8 @@ openai_api_key = "EMPTY"
60
  openai_api_base = "http://47.117.17.202:9999/v1"
61
 
62
 
63
- client = OpenAI(
64
- api_key=openai_api_key,
65
- base_url=openai_api_base,
66
- )
67
-
68
-
69
-
70
- def run_example(image, text_input=None):
71
-
72
- image_path = array_to_image_path(image)
73
- content = [
74
- {
75
- "type": "image_url",
76
- "image_url": {
77
- "url": f"data:image/jpeg;base64,{encode_image(image_path)}"
78
- }
79
- }
80
- ]
81
-
82
- # 可选文本内容
83
- if text_input is not None and text_input.strip():
84
- content.append(
85
- {
86
- "type": "text",
87
- "text": text_input
88
- }
89
- )
90
-
91
- messages = [
92
- {
93
- "role": "user",
94
- "content": content
95
- }
96
- ]
97
-
98
- response = client.chat.completions.create(
99
- model="Qwen2_5VL",
100
- messages=messages,
101
- extra_body={},
102
- extra_headers={
103
- "apikey": "empty"
104
- },
105
- stream=False,
106
- temperature=0.7,
107
- top_p=1.0,
108
- )
109
-
110
- return response.choices[0].message.content
111
 
112
-
113
-
114
- REVISION = 'v1.0.4'
115
  BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
116
  PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
117
 
@@ -203,11 +139,14 @@ def _launch_demo(args):
203
  "url": f"data:image/jpeg;base64,{encode_image(q[0])}"
204
  }
205
  })
206
- else:
207
  content.append({"type": "text", 'text': q})
208
  messages.append({'role': 'user', 'content': content})
209
  messages.append({'role': 'assistant', 'content': [{"type": "text", 'text': a}]})
210
  content = []
 
 
 
211
  messages.pop()
212
  responses = client.chat.completions.create(
213
  model="Qwen2_5VL",
@@ -286,9 +225,9 @@ def _launch_demo(args):
286
  return [], []
287
 
288
  with gr.Blocks() as demo:
289
- gr.Markdown("""<center><font size=3> Qwen2.5-VL-32B-Instruct Demo </center>""")
290
 
291
- chatbot = gr.Chatbot(label='Qwen2.5-VL-32B-Instruct', elem_classes="control-height", height=500)
292
  query = gr.Textbox(lines=2, label='Input')
293
  task_history = gr.State([])
294
 
 
2
  import time
3
  import os
4
  import sys
5
+ import re
6
  import json
7
  import base64
8
  import tqdm
9
  import base64
10
  from datetime import datetime
11
  import subprocess
12
+
 
 
13
  from pathlib import Path
14
  import numpy as np
15
  from PIL import Image
 
 
 
 
16
  from argparse import ArgumentParser
 
 
 
 
 
 
 
17
  import tempfile
 
 
18
 
19
 
20
  # Function to encode the image
 
46
  openai_api_base = "http://47.117.17.202:9999/v1"
47
 
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ REVISION = 'v0.0.1'
 
 
51
  BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
52
  PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
53
 
 
139
  "url": f"data:image/jpeg;base64,{encode_image(q[0])}"
140
  }
141
  })
142
+ elif q and q.strip():
143
  content.append({"type": "text", 'text': q})
144
  messages.append({'role': 'user', 'content': content})
145
  messages.append({'role': 'assistant', 'content': [{"type": "text", 'text': a}]})
146
  content = []
147
+ else:
148
+ continue
149
+
150
  messages.pop()
151
  responses = client.chat.completions.create(
152
  model="Qwen2_5VL",
 
225
  return [], []
226
 
227
  with gr.Blocks() as demo:
228
+ gr.Markdown("""<center><font size=3> Infinity-7B Demo </center>""")
229
 
230
+ chatbot = gr.Chatbot(label='Infinity-7B', elem_classes="control-height", height=500)
231
  query = gr.Textbox(lines=2, label='Input')
232
  task_history = gr.State([])
233