You-shen commited on
Commit
482f4a4
·
verified ·
1 Parent(s): 9a5fddc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -50
app.py CHANGED
@@ -40,56 +40,14 @@ def img_size(image):
40
  width = int(width)
41
  height = int(height)
42
  resized_img = image.resize((width, height))
43
- # resized_img.save(image_path)
44
  return resized_img
45
 
46
- # def search_image(query) -> str:
47
- # params = {
48
- # "engine": "google_images",
49
- # "q": query,
50
- # "gl": "cn",
51
- # }
52
- # search = GoogleSearch(params)
53
- # results = search.get_dict()
54
- # suggested_searches = results.get('suggested_searches', [])
55
- # if suggested_searches:
56
- # thumbnails = [search['thumbnail'] for search in suggested_searches][:3]
57
- # else:
58
- # thumbnails = []
59
- # # thumbnails = [search['thumbnail'] for search in results['suggested_searches']][:3]
60
- # information = ""
61
- # client = OpenAI()
62
- # for idx, thumbnail in enumerate(thumbnails):
63
- # response = client.chat.completions.create(
64
- # model="gpt-4o-mini",
65
- # messages=[
66
- # {
67
- # "role": "user",
68
- # "content": [
69
- # {"type": "text", "text": "What’s in this image?Give a brief answer"},
70
- # {
71
- # "type": "image_url",
72
- # "image_url": {
73
- # "url": thumbnail,
74
- # },
75
- # },
76
- # ],
77
- # }
78
- # ],
79
- # max_tokens=100,
80
- # )
81
- # response_content = response.choices[0].message.content
82
- # information = information + str(idx + 1) + ": " + response_content + "\n"
83
- # return (information)
84
-
85
 
86
  def encode_image(image):
87
- # image = Image.fromarray(image.astype("uint8"))
88
  buffered = io.BytesIO()
89
  image.save(buffered, format="PNG")
90
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
91
- # with open(image_path, "rb") as image_file:
92
- # return base64.b64encode(image_file.read()).decode("utf-8")
93
 
94
 
95
  def image_summarize(img_base64, prompt):
@@ -120,11 +78,6 @@ def generate_img_summaries(image):
120
  image_summaries.append(image_summarize(base64_image, prompt))
121
  return image_summaries
122
 
123
- # search_image = Tool(
124
- # name="Image Search", # 工具名称
125
- # func=search_image, # 引用search函数
126
- # description="搜索图片引擎,当你需要检索相关图片的时候调用,输入是检索query,输出是与query有关的图片的信息" # 工具描述
127
- # )
128
 
129
  en_prompt = """
130
  Remember, you are a false information verification tool developed by SCIR Laboratory at Harbin Institute of Technology
@@ -156,12 +109,12 @@ Use the following format:
156
  Question: The input content that needs to be verified
157
  Pre Thought: Briefly understand the content to be verified, whether it includes multiple details to be verified, and plan accordingly.
158
  Thought: What should you do to verify the first detail
159
- Action: One of the tool names in the tool list ({tool_name}) must not contain any other content
160
  Action Input: The input parameter for an Action
161
  Observation: The execution result of the Action
162
  ... (This' Thought/Action/Action Input/Observation 'logic can be repeated up to 3 times)
163
  Thought: I now know the final answer
164
- Final Answer: The verification result of the input content needs to be answered in Chinese
165
  Begin!
166
  Question: {input}
167
  Pre Thought: {agent_scratchpad}
 
40
  width = int(width)
41
  height = int(height)
42
  resized_img = image.resize((width, height))
 
43
  return resized_img
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  def encode_image(image):
 
47
  buffered = io.BytesIO()
48
  image.save(buffered, format="PNG")
49
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
50
+
 
51
 
52
 
53
  def image_summarize(img_base64, prompt):
 
78
  image_summaries.append(image_summarize(base64_image, prompt))
79
  return image_summaries
80
 
 
 
 
 
 
81
 
82
  en_prompt = """
83
  Remember, you are a false information verification tool developed by SCIR Laboratory at Harbin Institute of Technology
 
109
  Question: The input content that needs to be verified
110
  Pre Thought: Briefly understand the content to be verified, whether it includes multiple details to be verified, and plan accordingly.
111
  Thought: What should you do to verify the first detail
112
+ Action: One of the tool names in the tool list ({tool_names}) must not contain any other content
113
  Action Input: The input parameter for an Action
114
  Observation: The execution result of the Action
115
  ... (This' Thought/Action/Action Input/Observation 'logic can be repeated up to 3 times)
116
  Thought: I now know the final answer
117
+ Final Answer: The verification result of the input content needs to be answered in English
118
  Begin!
119
  Question: {input}
120
  Pre Thought: {agent_scratchpad}