Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
•
ee55620
1
Parent(s):
6c0ffcc
上传文件时自动总结
Browse files- ChuanhuChatbot.py +1 -1
- locale/en_US.json +3 -1
- locale/ja_JP.json +3 -1
- modules/models/base_model.py +18 -3
- modules/models/models.py +1 -1
ChuanhuChatbot.py
CHANGED
@@ -333,7 +333,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
333 |
submitBtn.click(**transfer_input_args).then(**chatgpt_predict_args, api_name="predict").then(**end_outputing_args)
|
334 |
submitBtn.click(**get_usage_args)
|
335 |
|
336 |
-
index_files.change(handle_file_upload, [current_model, index_files, chatbot], [index_files, chatbot, status_display])
|
337 |
|
338 |
emptyBtn.click(
|
339 |
reset,
|
|
|
333 |
submitBtn.click(**transfer_input_args).then(**chatgpt_predict_args, api_name="predict").then(**end_outputing_args)
|
334 |
submitBtn.click(**get_usage_args)
|
335 |
|
336 |
+
index_files.change(handle_file_upload, [current_model, index_files, chatbot, language_select_dropdown], [index_files, chatbot, status_display])
|
337 |
|
338 |
emptyBtn.click(
|
339 |
reset,
|
locale/en_US.json
CHANGED
@@ -70,5 +70,7 @@
|
|
70 |
"您的IP区域:未知。": "Your IP region: Unknown.",
|
71 |
"获取IP地理位置失败。原因:": "Failed to get IP location. Reason: ",
|
72 |
"。你仍然可以使用聊天功能。": ". You can still use the chat function.",
|
73 |
-
"您的IP区域:": "Your IP region: "
|
|
|
|
|
74 |
}
|
|
|
70 |
"您的IP区域:未知。": "Your IP region: Unknown.",
|
71 |
"获取IP地理位置失败。原因:": "Failed to get IP location. Reason: ",
|
72 |
"。你仍然可以使用聊天功能。": ". You can still use the chat function.",
|
73 |
+
"您的IP区域:": "Your IP region: ",
|
74 |
+
"总结": "Summarize",
|
75 |
+
"生成内容总结中……": "Generating content summary..."
|
76 |
}
|
locale/ja_JP.json
CHANGED
@@ -70,5 +70,7 @@
|
|
70 |
"您的IP区域:未知。": "あなたのIPアドレス地域:不明",
|
71 |
"获取IP地理位置失败。原因:": "IPアドレス地域の取得に失敗しました。理由:",
|
72 |
"。你仍然可以使用聊天功能。": "。あなたはまだチャット機能を使用できます。",
|
73 |
-
"您的IP区域:": "あなたのIPアドレス地域:"
|
|
|
|
|
74 |
}
|
|
|
70 |
"您的IP区域:未知。": "あなたのIPアドレス地域:不明",
|
71 |
"获取IP地理位置失败。原因:": "IPアドレス地域の取得に失敗しました。理由:",
|
72 |
"。你仍然可以使用聊天功能。": "。あなたはまだチャット機能を使用できます。",
|
73 |
+
"您的IP区域:": "あなたのIPアドレス地域:",
|
74 |
+
"总结": "要約する",
|
75 |
+
"生成内容总结中……": "コンテンツ概要を生成しています..."
|
76 |
}
|
modules/models/base_model.py
CHANGED
@@ -178,12 +178,27 @@ class BaseLLMModel:
|
|
178 |
status_text = self.token_message()
|
179 |
return chatbot, status_text
|
180 |
|
181 |
-
def handle_file_upload(self, files, chatbot):
|
182 |
"""if the model accepts multi modal input, implement this function"""
|
183 |
status = gr.Markdown.update()
|
184 |
if files:
|
185 |
-
construct_index(self.api_key, file_src=files)
|
186 |
-
status = "索引构建完成"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
return gr.Files.update(), chatbot, status
|
188 |
|
189 |
def prepare_inputs(self, real_inputs, use_websearch, files, reply_language, chatbot):
|
|
|
178 |
status_text = self.token_message()
|
179 |
return chatbot, status_text
|
180 |
|
181 |
+
def handle_file_upload(self, files, chatbot, language):
|
182 |
"""if the model accepts multi modal input, implement this function"""
|
183 |
status = gr.Markdown.update()
|
184 |
if files:
|
185 |
+
index = construct_index(self.api_key, file_src=files)
|
186 |
+
status = i18n("索引构建完成")
|
187 |
+
# Summarize the document
|
188 |
+
logging.info(i18n("生成内容总结中……"))
|
189 |
+
os.environ["OPENAI_API_KEY"] = self.api_key
|
190 |
+
from langchain.chains.summarize import load_summarize_chain
|
191 |
+
from langchain.prompts import PromptTemplate
|
192 |
+
from langchain.chat_models import ChatOpenAI
|
193 |
+
from langchain.callbacks import StdOutCallbackHandler
|
194 |
+
prompt_template = "Write a concise summary of the following:\n\n{text}\n\nCONCISE SUMMARY IN " + language + ":"
|
195 |
+
PROMPT = PromptTemplate(template=prompt_template, input_variables=["text"])
|
196 |
+
handler = StdOutCallbackHandler()
|
197 |
+
llm = ChatOpenAI(callbacks=[handler])
|
198 |
+
chain = load_summarize_chain(llm, chain_type="map_reduce", return_intermediate_steps=True, map_prompt=PROMPT, combine_prompt=PROMPT)
|
199 |
+
summary = chain({"input_documents": list(index.docstore.__dict__["_dict"].values())}, return_only_outputs=True)["output_text"]
|
200 |
+
print(i18n("总结") + f": {summary}")
|
201 |
+
chatbot.append([i18n("总结"), summary])
|
202 |
return gr.Files.update(), chatbot, status
|
203 |
|
204 |
def prepare_inputs(self, real_inputs, use_websearch, files, reply_language, chatbot):
|
modules/models/models.py
CHANGED
@@ -494,7 +494,7 @@ class XMChat(BaseLLMModel):
|
|
494 |
limited_context = False
|
495 |
return limited_context, fake_inputs, display_append, real_inputs, chatbot
|
496 |
|
497 |
-
def handle_file_upload(self, files, chatbot):
|
498 |
"""if the model accepts multi modal input, implement this function"""
|
499 |
if files:
|
500 |
for file in files:
|
|
|
494 |
limited_context = False
|
495 |
return limited_context, fake_inputs, display_append, real_inputs, chatbot
|
496 |
|
497 |
+
def handle_file_upload(self, files, chatbot, language):
|
498 |
"""if the model accepts multi modal input, implement this function"""
|
499 |
if files:
|
500 |
for file in files:
|