#!/usr/bin/env python # -*- coding:utf-8 _*- """ @author:quincy qiang @license: Apache Licence @file: main.py @time: 2023/04/17 @contact: yanqiangmiffy@gamil.com @software: PyCharm @description: coding.. """ import os import shutil import gradio as gr from clc.langchain_application import LangChainApplication # 修改成自己的配置!!! class LangChainCFG: llm_model_name = '../../pretrained_models/chatglm-6b' # 本地模型文件 or huggingface远程仓库 embedding_model_name = '../../pretrained_models/text2vec-large-chinese' # 检索模型文件 or huggingface远程仓库 vector_store_path = './cache' docs_path = './docs' config = LangChainCFG() application = LangChainApplication(config) def get_file_list(): if not os.path.exists("docs"): return [] return [f for f in os.listdir("docs")] file_list = get_file_list() def upload_file(file): if not os.path.exists("docs"): os.mkdir("docs") filename = os.path.basename(file.name) shutil.move(file.name, "docs/" + filename) # file_list首位插入新上传的文件 file_list.insert(0, filename) application.source_service.add_document("docs/" + filename) return gr.Dropdown.update(choices=file_list, value=filename) def clear_session(): return '', None def predict(input, large_language_model, embedding_model, history=None): print(large_language_model, embedding_model) if history == None: history = [] resp = application.get_knowledge_based_answer( query=input, history_len=5, temperature=0.1, top_p=0.9, chat_history=history ) print(resp) history.append((input, resp['result'])) return '', history, history block = gr.Blocks() with block as demo: gr.Markdown("""