File size: 22,129 Bytes
0cb8127
170b9e3
 
 
 
 
 
048eef5
170b9e3
 
1d80acf
170b9e3
 
 
 
1d80acf
 
d22e8cd
1d80acf
 
170b9e3
 
 
1d80acf
d22e8cd
1d80acf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b196d1
1d80acf
4b196d1
 
 
 
 
1d80acf
 
170b9e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d80acf
170b9e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111620d
 
 
 
204c5db
111620d
347f513
111620d
 
 
 
 
 
 
 
 
 
 
 
 
 
347f513
111620d
 
 
 
 
 
 
 
 
 
 
204c5db
111620d
347f513
111620d
 
 
 
 
 
 
 
 
 
 
 
 
 
347f513
111620d
 
 
 
 
 
 
 
 
 
 
204c5db
111620d
347f513
111620d
 
 
 
 
 
 
 
 
 
 
 
 
 
347f513
111620d
 
 
 
 
 
 
 
 
 
 
204c5db
111620d
347f513
111620d
 
 
 
 
 
 
 
 
 
 
 
 
 
347f513
111620d
 
 
 
 
 
 
 
 
 
 
204c5db
111620d
347f513
111620d
 
 
 
 
 
 
 
 
 
 
 
 
 
347f513
111620d
 
 
 
 
 
 
 
 
 
 
204c5db
111620d
347f513
111620d
 
 
 
 
 
 
 
 
 
 
 
 
 
347f513
111620d
 
 
 
 
 
 
 
 
 
 
170b9e3
204c5db
170b9e3
347f513
111620d
 
 
 
 
 
 
 
 
 
 
 
 
 
347f513
111620d
 
 
4b196d1
111620d
 
 
 
 
 
 
 
 
 
347f513
4646690
 
4b196d1
 
 
 
 
 
 
 
 
 
 
 
111620d
4b196d1
 
 
 
df32d48
4b196d1
 
0370219
 
4b196d1
 
 
 
170b9e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3494a0
 
 
 
 
 
 
8ce62b2
170b9e3
111620d
170b9e3
 
111620d
 
 
 
c3494a0
111620d
 
 
170b9e3
 
 
 
 
 
 
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# -*- coding: gbk -*-
import gradio as gr
#from huggingface_hub import InferenceClient

import os
from pathlib import Path
from openai import OpenAI
import time
class ChatgptAPI:
    def __init__(self, ):
        '''
        self.client = OpenAI(
            api_key = os.environ.get("OPENAI_API_KEY"),
            base_url = "https://api.moonshot.cn/v1",
        )
        '''
        self.client=OpenAI(
            api_key=os.environ.get("TONGYI_API_KEY"),  # �滻����ʵDashScope��API_KEY
            base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",  # ��дDashScopebase_url
        )  
        
        
    def get_summary(self, file_path):
        file = self.client.files.create(file=Path(file_path), purpose="file-extract")
        completion = self.client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '����������ѯ����ר�ң�����Ҫ����ѯʦ����ѯ���ݽ��ж�������Ҫ������ѯʦ�Ļػ�����Ϊ�������Dz���ȷ�ġ�step by step������²��裺\n ����1-�򿪲��Ķ����ϴ����ı��ļ���ȫ�����ݣ�ֱ�����һ���ַ� \n ����2-��ȫ����ժȡ�����ߵġ��ؼ��Է��ԡ�����Ҫ��ժ¼�ı�ǰ�벿�ֵķ��ԣ�����ѡ����������Ҫ�����۵�3-4������¼���Խ������һ����ѯʦ����Ļظ�����Ϊ����ѯʦ�Ļظ��� \n ����3-��Թؼ��Է��ԣ��������ʵġ������ػ����ݡ� \n ����4-�Աȡ������ػ����ݡ��͡���ѯʦ�Ļظ���������ÿ���Ӧ��֣�0��Ϊ�붽���ػ�������ȫ��һ�£�10���붽���ػ�������ȫһ�£� \n ����5-����4����ִ�в��������������json��ʽ����� [{"key_num" : "n", "visiter" : "����������", "superior" : "�����ػ���������", "adviser" : "��ѯʦ�Ļظ�����",��"score" : "x/10", "reason" : "�޸�ԭ������"}]'
                } 
            ],
            stream=True
        )
        for chunk in completion:
            if chunk.choices[0].delta.content is not None:
                print(chunk.choices[0].dict())
        #message=completion.choices[0].message.dict()['content']
        #return message

        '''
        file_object = self.client.files.create(file=Path(file_path), purpose="file-extract")
        file_content = self.client.files.content(file_id=file_object.id).text
        messages = [
            {
                "role": "system",
                "content": "���� Kimi���� Moonshot AI �ṩ���˹��������֣�����ó����ĺ�Ӣ�ĵĶԻ������Ϊ�û��ṩ��ȫ���а�����׼ȷ�Ļش�ͬʱ�����ܾ�һ���漰�ֲ����壬�������ӣ���ɫ����������Ļش�Moonshot AI Ϊר�����ʣ����ɷ�����������ԡ�",
            },
            {
                "role": "system",
                "content": file_content,
            },
            {"role": "user", "content": "��д���ܽ�"},
        ]
        completion = self.client.chat.completions.create(
            model="moonshot-v1-32k",
            messages=messages,
            temperature=0.3,
        )
        message=completion.choices[0].message.content
        return message
        '''
        
    def get_single_round_completion(self, file_path, prompt, conversation):
        conversation.append_question(prompt)
        file_object = self.client.files.create(file=Path(file_path), purpose="file-extract")
        file_content = self.client.files.content(file_id=file_object.id).text
        messages = [
            {
                "role": "system",
                "content": "���� Kimi���� Moonshot AI �ṩ���˹��������֣�����ó����ĺ�Ӣ�ĵĶԻ������Ϊ�û��ṩ��ȫ���а�����׼ȷ�Ļش�ͬʱ�����ܾ�һ���漰�ֲ����壬�������ӣ���ɫ����������Ļش�Moonshot AI Ϊר�����ʣ����ɷ�����������ԡ�",
            },
            {
                "role": "system",
                "content": file_content,
            },
            {"role": "user", "content": prompt},
        ]
        completion = self.client.chat.completions.create(
            model="moonshot-v1-32k",
            messages=messages,
            temperature=0.3,
        )
        message=completion.choices[0].message.content
        conversation.append_answer(message)
        return message, conversation
        
    
    def get_multi_round_completion(self, prompt, conversation, model='gpt-3.5-turbo'):
        conversation.append_question(prompt)
        prompts = conversation.get_prompts()

        response = openai.ChatCompletion.create(
            model=model,
            messages=prompts,
            temperature=0,
            max_tokens=2048,
            top_p=1,
        )
        message = response.choices[0].message['content']
        conversation.append_answer(message)

        return message, conversation

class Conversation:
    def __init__(self, system_prompt='iii', num_of_round = 5):
        self.num_of_round = num_of_round
        self.history = []
        self.initialized = False
        self.history.append({"role": "system", "content": system_prompt})

        if len(system_prompt) > 0:
            #logger.info(f'Conversation initialized with system prompt: {system_prompt}')
            self.initialized = True

    def is_initialized(self):
        return self.initialized
    
    def append_question(self, question):
        self.history.append({"role": "user", "content": question})

    def append_answer(self, answer):
        self.history.append({"role": "assistant", "content": answer})

        if len(self.history) > self.num_of_round * 2:
            del self.history[1:3]

    def clear(self):
        self.history.clear()
        self.initialized = False

    def get_prompts(self):
        return self.history
    
    def round_size(self):
        return 0 if len(self.history) < 2 else len(self.hitory) - 1
    
    def get_history_messages(self):
        return [(u['content'], b['content']) for u,b in zip(self.history[1::2], self.history[2::2])]



chat_api = ChatgptAPI()
client=OpenAI(
        api_key=os.environ.get("TONGYI_API_KEY"),  # �滻����ʵDashScope��API_KEY
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",  # ��дDashScopebase_url
)
def predict_issue(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '������ѯ�ĸ����ݣ������ѯ�������ݵ��������ܽᣬ�ֱ���һ�仰�����������ߵģ�1����Ҫ���⣺���������ߵ�ǰ������������֡�\n 2��������Ϣ����������������Ҫ������صı�����Ϣ��\n 3�����������ߣ�����������ǰ����ѯ����Ҫ������ڴ���\n 4����ѯ����������������ǰ����ѯ����Ҫ������\n �������ڸ���¼��������������ݡ�ע�⣺��д���ݺ�ֹͣһ����������������ܽᡣ'
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history
def predict_mindmap(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '��������������ѯ����ר�ң�����Ҫ����ѯʦ����ѯ���ݽ��ж�����������ѯ���̽��зֶκͶ�����������ٰ���2-4����Ҫ��֧��ÿ����Ҫ��֧����2-4����Ҫ��֧'
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history
def predict_keywords(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '������ѯ�ĸ����ݣ������½Ƕȷ��������ߵ����ʣ�1����������ѧ�����������ߵ����ij�ͻ���������ơ����״̬�Լ��������Ӱ����Ϊ��2���˸����ʣ��������õĿ����ԡ������ԡ������ԡ������ԡ������ȶ��ԡ������˸�������Ӧ��������ύ���Ͷ������ֵ�ۡ�3����֪ģʽ�����������ߵ�˼άģʽ��������֪ƫ�������ϵ�ȡ�4������״̬�����������ߵ������ȶ��ԡ��������﷽ʽ�Լ���������������5����Ϊģʽ�����������ߵ���Ϊϰ�ߡ�Ӧ�Բ����Լ���Ϊ�Ե�ǰ�����Ӱ�졣6��Ӧ����Դ��Ӧ�Է�ʽ�����������߿��õ���Դ��Ӧ��ѹ���ķ�ʽ�����񣺷ֱ����������֪����Ϊ�͹�ϵ�ĸ����棬��ȡ�����߹ؼ����ʣ�������3-4���ؼ��ʡ������¸�ʽ�����1������ \n �ؼ����ʣ������������� \n �ؼ��ʣ����ǡ��������־�'
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history
def predict_dynamics(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '����������ѯ����ר�ң�����Ҫ����ѯʦ����ѯ���ݽ��ж���������1���򿪲��Ķ����ϴ����ı��ļ���ȫ����ѯ���ݣ�ֱ�����һ���ַ�������2 ���������¿�ܶ���ѯ�������֣�0��Ϊ��ȫ�����ϣ�10��Ϊ��ȫ���ϣ�����¼���ֺ�ԭ�����ı���δ�ἰ������ݿɺ������֣�1����������ѯʦ�Ƿ���Ч�ؿ�������ȷ�˱�����ѯ��Ŀ�ĺ�Ԥ�ڡ�2��������ϵ����ѯʦ�Ƿ�����ѯ��ʼʱ�����˻����Ĺ�����ϵ��\n �ͻ��Ƿ�е������������⡣3�������͹�ͨ����ѯʦ�Ƿ�չ�ֳ��������������ɣ������̽�������ߵĸ��ܣ�����������ͣ���ڱ������ͬ��\n ��ͨ�Ƿ����������������������������ҹ����������Լ����֡���������Լ��ĸ��ܺ���Ϊ��4������֧�֣��Ƿ����������ʶ��ʹ�����������������̽�������ߵ����������ԭ��\n ��ѯʦ�Ƿ��ṩ���ʵ���������Ӧ��֧�֡�5��Ŀ��۽����Ƿ�Χ�Ƽȶ�Ŀ�������ѯ��\n Ŀ���Ƿ��ʺ������ߵ�ǰ�������������õ���ͬ�Ͳ��롣6����Ԥʵʩ����ѯʦ�Ƿ�ʹ���˺��ʵĸ�Ԥ���ԡ�\n ��Ԥ�ͼ���ʹ���Ƿ���ͻ�����Ҫ��Ŀ�������7���仯���������������߶Ի�̸�ķ�Ӧ��������С���֪����Ϊ�ϵı仯�� \n  �����ڻ�̸������Ŀ���ʵ�̶ֳȣ��������Ƿ�������չ��8���������ܽ᣺��ѯʦ�Ƿ��ṩ�˼�ʱ�ķ�����\n ��ѯʦ�Ƿ�չ�ֳ����Լ���Ϊ�ͷ�Ӧ����ʶ��9����̸�Ľṹ��������̸�Ƿ��������Ľṹ���������롢�������ۺ��ܽ�Ȳ��֡�\n ������̸�������ԣ������Ի��������Ժ�ת������Ȼ�ԡ�10�������������Ƿ���Ȼ���Ƿ�����Ч���ܽᣬ�������Ƿ�õ������õķ�����\n  �Ƿ�Ϊ��һ����ѯ������ж�������������ָ�����Ƿ��������߲��뵽����ܽ����������ǿ�����ߵIJ���к���ѯ�ĸ��Ի�������3������2��������������¸�ʽ�����1��������ϵ��\n  ���֣���\n ԭ�򣨾����������ԭ�ķ�������'
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history
def predict_complaint(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '��Ϊ�������������ר�ң����ڽ�����ѯ���ߺͻ�̸Ŀ�����ʱ����������¿�������������������ߵ������1������������ \n��Ҫ���⣺���������ߵ�ǰ������������֡�\n  ������Ϣ����������������Ҫ������صı�����Ϣ��\n  ���������ߣ�����������ǰ����ѯ����Ҫ������ڴ���\n ��ѯ����������������ǰ����ѯ����Ҫ������\n �������ڸ���¼��������������ݡ�ע�⣺��д���ݺ�ֹͣһ����������������ܽᡣ'
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history
def predict_concept(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '��Ϊ�������������ר�ң����ڽ��и������ʱ����������¿�������������������ߵ������1���˿�ͳ��ѧ��Ϣ�����������ߵ����䡢�Ա����塢����������ְҵ״̬�Ȼ�����Ϣ��2����չʷ�����������ߵijɳ�������������ͥ���������ھ������������̵ȡ�3�����������ʷ�����������ߵ���Ҫ�����¼����˼ʹ�ϵ�����֧��ϵͳ�ȡ�4����������ʷ�����������ߵ���������״����������ȥ�����ڵ��������⡢������ʷ�ȡ�5����������ѧ�����������ߵ����ij�ͻ���������ơ����״̬�Լ��������Ӱ����Ϊ��6�������ʣ��������õĿ����ԡ������ԡ������ԡ������ԡ������ȶ��ԡ������˸�������Ӧ��������ύ�����������ֵ�ۡ�7����֪ģʽ�����������ߵ�˼άģʽ��������֪ƫ�������ϵ�ȡ�8������״̬�����������ߵ������ȶ��ԡ��������﷽ʽ�Լ���������������9����Ϊģʽ�����������ߵ���Ϊϰ�ߡ�Ӧ�Բ����Լ���Ϊ�Ե�ǰ�����Ӱ�졣10��Ӧ����Դ��Ӧ�Է�ʽ�����������߿��õ���Դ��Ӧ��ѹ���ķ�ʽ��11����ǰ����״��������������Ŀǰ������״�����繤����ѧϰ����ͥ����罻�˼ʻ�ȡ�12�����ӡ���г���ص����ӡ�󣬰���DSM������ᡣ13���������������������߿��ܴ��ڵķ������أ�����ɱ���ա������˺����յȡ��������ڸ���¼������������������漰��������ʱʹ�����¸�ʽ���������߻ػ�����ض��䣨{�����á�����}���������������ܽᡣ'
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history

def predict_plan(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '�����������������ר�ң������ƶ�δ����ѯ�ƻ��Ĺ滮ʱ��ͨ�����������¼������ά�������У�1�����Ƽƻ���ά��1����ǰ״������ - ���ݱ��λ�̸���ݣ����������ߵ�����״̬����֪ģʽ����Ϊ�����Լ���Ṧ�ܡ� \n  ά��2��Ŀ��ϸ�� - ����Զ������Ŀ��ϸ��Ϊ���ڿɴ�ɵ�СĿ�꣬ȷ��Ŀ��Ŀɲ����Ժ���ʵ���ԡ�\nά��3����Ԥ��ʩѡ�� - ���������ߵ������ƫ�ã�ѡ����ʵ�������Ԥ��ʩ������֪��Ϊ���ơ���������ѧ���ơ�����������Ƶȡ�\n  2���´λ�̸Ŀ�꣺������ѯ���ݣ���ȡ��ѯʦ������������ѯ�д��һ�£�˫����ͬԸ��Ŭ���ĺ��Ļ�̸Ŀ�ꡣ1-3�㡣\n ά��1���ع������� - �ع˱��λ�̸�Ĺؼ��㣬���������ߵķ�����ǿ���������ˡ�\nά��2��δ�����������̽�� - ��Ա�����ѯ��δ��ȫ�����������³��ֵ����⣬���и������̽�ֺͷ�����\n ά��3��������ϰ��Ӧ�� - �����������ض���Ӧ�Լ��ɻ��������ʼ��ܣ����������ճ������е�ʵ��Ӧ�á�\n �������ڸ���¼������������������������ܽ�'
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history

def predict_highlight(password_input, user_in_file):
    if password_input != os.environ.get("USER_KEY"):
       return [(None, "Wrong password!")]
    file = client.files.create(file=Path(user_in_file), purpose="file-extract")
    completion = client.chat.completions.create(
            model="qwen-long",
            messages=[
                {
                    'role': 'system',
                    'content': 'You are a helpful assistant.'
                },
                {
                    'role': 'system',
                    'content': f'fileid://{file.id}'
                },
                {
                    'role': 'user',
                    'content': '����������ѯ����ר�ң�����Ҫ����ѯʦ����ѯ���ݽ��ж�������Ҫ������ѯʦ�Ļػ�����Ϊ�������Dz���ȷ�ġ�step by step������²��裺\n ����1-�򿪲��Ķ����ϴ����ı��ļ���ȫ�����ݣ�ֱ�����һ���ַ� \n ����2-��ȫ����ժȡ�����ߵġ��ؼ��Է��ԡ�����Ҫ��ժ¼�ı�ǰ�벿�ֵķ��ԣ�����ѡ����������Ҫ�����۵�3-4������¼���Խ������һ����ѯʦ����Ļظ�����Ϊ����ѯʦ�Ļظ��� \n ����3-��Թؼ��Է��ԣ��������ʵġ������ػ����ݡ� \n ����4-�Աȡ������ػ����ݡ��͡���ѯʦ�Ļظ���������ÿ��ش�֣�0��Ϊ�붽���ػ�������ȫ��һ�£�10���붽���ػ�������ȫһ�£� \n ����5-����4����ִ�в�������������¸�ʽ�����- �ؼ��Է���n��,\n - �����ߣ�,\n , - �����ػ�������, \n , - ��ѯʦ�Ļظ��� ,\n , - ���֣�x/10 \n ,- �޸�ԭ�� '
                }
            ],
            stream=True
    )
    history=""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].dict())
            history += chunk.choices[0].delta.content
            time.sleep(0.05)
            yield history
    #conversation = chat_api.get_summary(user_in_file)
    #return conversation
    




with gr.Blocks(css="#chatbot{height:350px} .overflow-y-auto{height:600px}") as demo:

    with gr.Row():
        system_in_txt = gr.Textbox(lines=1, label="User Name:", placeholder="Enter user name")
        password_in_txt = gr.Textbox(lines=1, label="Password:", placeholder="Enter password")
       
    with gr.Row():
        with gr.Column(scale=1, min_width=50):
            user_in_file = gr.File(label="Upload File")
            #submit_button = gr.Button("Submit")
            issue_button = gr.Button("��ѯ����")
            mindmap_button = gr.Button("˼ά��ͼ")
            keywords_button = gr.Button("��ѯ�ؼ���")
            dynamics_button = gr.Button("��̸��̬")
            concept_button = gr.Button("�������")
            highlight_button = gr.Button("�Ի�����")
            plan_button = gr.Button("�����ƻ�")
            
        with gr.Column(scale=2):
            system_in_txt = gr.Textbox(lines=30, label="Output Text:")
    
    
    issue_button.click(fn=predict_issue, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    mindmap_button.click(fn=predict_mindmap, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    keywords_button.click(fn=predict_keywords, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    dynamics_button.click(fn=predict_dynamics, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    ##complaint_button.click(fn=predict_complaint, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    concept_button.click(fn=predict_concept, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    highlight_button.click(fn=predict_highlight, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    plan_button.click(fn=predict_plan, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
    #submit_button.click(predict, [system_in_txt, password_in_txt, user_in_file, user_in_txt, conversation], [chatbot, conversation, user_in_txt])
    #reset_button.click(clear_history, [conversation], [chatbot, conversation], queue=False)


if __name__ == "__main__":
    demo.launch()