AUST001 commited on
Commit
ddfea9d
·
1 Parent(s): 5bec054

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -19
app.py CHANGED
@@ -1,6 +1,4 @@
1
  from pickle import NONE
2
- import numpy as np
3
- import cv2
4
  import urllib.request
5
  import openai
6
  import gradio as gr
@@ -51,24 +49,9 @@ def greet(user_id, api_key, user_question, clear_history):
51
  {"role": "assistant", "content": "是的,我可以说中文。"}
52
  ]
53
  user_contexts[user_id] = context
54
- return '清空成功', '保持聊天记录', np.ones((5,5))
55
  else:
56
- # 如果user提问包含生成图像的特定指令(这里我们使用“生成图片:”作为示例)
57
- if user_question.startswith("生成图片:") or user_question.startswith("生成图片:"):
58
- image_prompt = user_question[5:] # 提取用于生成图片的文本
59
- image_url = generate_image_url(image_prompt)
60
- resp = urllib.request.urlopen(image_url)
61
- image = np.asarray(bytearray(resp.read()), dtype="uint8")
62
- image = cv2.imdecode(image, cv2.IMREAD_COLOR)
63
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
64
- # return image
65
- return '', '图片已生成', image
66
- get_assistant_response(user_question, context)
67
- prompt = ""
68
-
69
- for item in context[3:]:
70
- prompt += item["role"] + ": " + item["content"] + "\n"
71
- return '', prompt, np.ones((5,5))
72
 
73
  demo = gr.Interface(
74
  fn=greet,
 
1
  from pickle import NONE
 
 
2
  import urllib.request
3
  import openai
4
  import gradio as gr
 
49
  {"role": "assistant", "content": "是的,我可以说中文。"}
50
  ]
51
  user_contexts[user_id] = context
52
+ return '清空成功', '保持聊天记录'
53
  else:
54
+ pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  demo = gr.Interface(
57
  fn=greet,