Upload folder using huggingface_hub
Browse filesFiles changed (11)
- .gitignoreAdded+138
- README.en.mdAdded+36
- README.md+40-7
- app1/code_block.pyAdded+51
- app1/config_test.pyAdded+26
- app1/generate_combinations.pyAdded+52
- app1/gpt_chat_handler_test.pyAdded+102
- app1/main_test.pyAdded+164
- app1/res.xlsxAdded
- app1/utils_test.pyAdded+9
- flagged/log.csvAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138# Byte-compiled / optimized / DLL files__pycache__/*.py[cod]*$py.class
# C extensions*.so
# Distribution / packaging.Pythonbuild/develop-eggs/dist/downloads/eggs/.eggs/lib/lib64/parts/sdist/var/wheels/share/python-wheels/*.egg-info/.installed.cfg*.eggMANIFEST
# PyInstaller# Usually these files are written by a python script from a template# before PyInstaller builds the exe, so as to inject date/other infos into it.*.manifest*.spec
# Installer logspip-log.txtpip-delete-this-directory.txt
# Unit test / coverage reportshtmlcov/.tox/.nox/.coverage.coverage.*.cachenosetests.xmlcoverage.xml*.cover*.py,cover.hypothesis/.pytest_cache/cover/
# Translations*.mo*.pot
# Django stuff:*.loglocal_settings.pydb.sqlite3db.sqlite3-journal
# Flask stuff:instance/.webassets-cache
# Scrapy stuff:.scrapy
# Sphinx documentationdocs/_build/
# PyBuilder.pybuilder/target/
# Jupyter Notebook.ipynb_checkpoints
# IPythonprofile_default/ipython_config.py
# pyenv# For a library or package, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# .python-version
# pipenv# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.# However, in case of collaboration, if having platform-specific dependencies or dependencies# having no cross-platform support, pipenv may install dependencies that don't work, or not# install all needed dependencies.#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow__pypackages__/
# Celery stuffcelerybeat-schedulecelerybeat.pid
# SageMath parsed files*.sage.py
# Environments.env.venvenv/venv/ENV/env.bak/venv.bak/
# Spyder project settings.spyderproject.spyproject
# Rope project settings.ropeproject
# mkdocs documentation/site
# mypy.mypy_cache/.dmypy.jsondmypy.json
# Pyre type checker.pyre/
# pytype static type analyzer.pytype/
# Cython debug symbolscython_debug/123456789101112131415161718192021222324252627282930313233343536# llm
#### Description{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software ArchitectureSoftware architecture description
#### Installation
1. xxxx2. xxxx3. xxxx
#### Instructions
1. xxxx2. xxxx3. xxxx
#### Contribution
1. Fork the repository2. Create Feat_xxx branch3. Commit your code4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md2. Gitee blog [blog.gitee.com](https://blog.gitee.com)3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)4. The most valuable open source project [GVP](https://gitee.com/gvp)5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)123456789101112---title: Llmemoji: 🐢colorFrom: bluecolorTo: redsdk: gradiosdk_version: 4.39.0app_file: app.pypinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021222324252627282930313233343536373839404142434445---title: llmapp_file: app1/demo.pysdk: gradiosdk_version: 4.39.0---# llm#### 介绍{**以下是 Gitee 平台说明,您可以替换此简介**Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}#### 软件架构软件架构说明#### 安装教程1. xxxx2. xxxx3. xxxx#### 使用说明1. xxxx2. xxxx3. xxxx#### 参与贡献1. Fork 本仓库2. 新建 Feat_xxx 分支3. 提交代码4. 新建 Pull Request#### 特技1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051```pythonimport pandas as pdimport itertools
# 约束条件SUM_CONSTRAINT = 100MIN_NON_ZERO = 2MAX_ZERO = 5MIN_SUM_X3_X4_X8_X9 = 35MAX_SUM_X3_X4_X8_X9 = 80RANGE = range(0, 41, 10) # x1~x9的最小值和最大值范围,步长为10
# 生成可能的组合def cartesian_product(*arrays): return list(itertools.product(*arrays))
# 检查组合是否满足约束条件def is_valid_combination(combination): # 条件1: x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 = 100 if sum(combination) != SUM_CONSTRAINT: return False # 条件2: 至少两个不为0,至多5个为0 non_zero_count = sum(1 for x in combination if x != 0) if non_zero_count < MIN_NON_ZERO or non_zero_count > 9 - MAX_ZERO: return False # 条件3: 35 <= x3 + x4 + x8 + x9 <= 80 sum_x3_x4_x8_x9 = sum(combination[2:6:3]) # x3, x4, x8, x9 if not MIN_SUM_X3_X4_X8_X9 <= sum_x3_x4_x8_x9 <= MAX_SUM_X3_X4_X8_X9: return False # 条件4: x1, x2, x3, x4, x5, x6, x7, x8, x9的最小值为0,最大值为40,步长为10 for x in combination: if x not in RANGE: return False return True
# 生成所有可能的组合all_ranges = [RANGE for _ in range(9)]all_combinations = cartesian_product(*all_ranges)
# 过滤符合条件的组合valid_combinations = [combination for combination in all_combinations if is_valid_combination(combination)]
# 创建DataFramedf = pd.DataFrame(valid_combinations, columns=['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9'])
print(df)```1234567891011121314151617181920212223242526#!/usr/bin/env python# -*- coding: utf-8 -*-"""@Author: 木羽Cheney@Date: 2024-05-23@Description: """
openai_api_key = "sk-proj-eMt3N5HlMyVD8Njk5d8pT3BlbkFJLGIfdJEx32LdIP21MhjD"
LLM_MODELS = [ "GLM-4", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-3.5-turbo-0125", "gpt-3.5-turbo",]
QDRANT_HOST = "localhost"QDRANT_POPT = 6333QDRANT_SIZE = 1536
FILE_SUFFIX = ['.pdf']12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import pandas as pdfrom itertools import product
# 约束条件TOTAL_SUM = 100MIN_NON_ZERO = 2MAX_ZERO = 5MIN_SUM_X3X4X8X9 = 35MAX_SUM_X3X4X8X9 = 80RANGE_MIN = 0RANGE_MAX = 40STEP = 10
# 生成可能的取值列表value_list = [i for i in range(RANGE_MIN, RANGE_MAX+1, STEP)]
# 笛卡尔积组合生成器def cartesian_product(*args): return product(*args)
# 检查是否满足约束条件def check_constraints(row): # 约束1: 总和等于100 if sum(row) != TOTAL_SUM: return False # 约束2: 至少两个不为0,至多5个为0 non_zeros = sum(1 for x in row if x != 0) if non_zeros < MIN_NON_ZERO or non_zeros > 9 - MAX_ZERO: return False # 约束3: x3 + x4 + x8 + x9 的值在35到80之间 if not MIN_SUM_X3X4X8X9 <= row[2] + row[3] + row[7] + row[8] <= MAX_SUM_X3X4X8X9: return False # 约束4: x1、x2、x3、x4、x5、x6、x7、x8、x9的最小值为0,最大值为40,步长为10 if not all(x in value_list for x in row): return False return True
# 生成笛卡尔积并筛选满足条件的样本cartesian_product_values = cartesian_product(value_list, repeat=9)valid_samples = [row for row in cartesian_product_values if check_constraints(row)]
# 转换为DataFramedf_result = pd.DataFrame(valid_samples, columns=['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9'])
# 保存结果df_result.to_excel('res.xlsx', index=False)
print("样本空间已生成并保存为 'res.xlsx'")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102# import os# from openai import OpenAI# # api_key = 'sk-proj-eMt3N5HlMyVD8Njk5d8pT3BlbkFJLGIfdJEx32LdIP21MhjD'# # client = OpenAI(# # api_key=os.environ.get("OPENAI_API_KEY"),# # )
# def create_chat_response(messages):# # client = OpenAI(api_key= 'sk-proj-eMt3N5HlMyVD8Njk5d8pT3BlbkFJLGIfdJEx32LdIP21MhjD'), # # completion = client.chat.completions.create(# # model="gpt-4",# # messages=messages# # )
# client = OpenAI(api_key='sk-proj-XknFnWCLdlZ2j4yQkwZRT3BlbkFJviDn2nJGbHOYsww75l38')# completion = client.chat.completions.create(# model="gpt-4",# messages=[# {"role": "system", "content": "你是一位乐于助人的AI小助理"},# {"role": "user", "content": "你好,请你介绍一下你自己"}# ]# )
# return completion.choices[0].message.contentimport re def remove_code_fences(code_string): # 正则表达式匹配 ```python 和 ``` 标记 pattern = re.compile(r"```python\n|```$", re.MULTILINE) # 使用正则表达式替换掉匹配到的标记 cleaned_code = re.sub(pattern, "", code_string) return cleaned_code
def create_chat_response(messages): api_key = "292c872d3a0cfb2b1c4cfc747a043b46.4SRZWack4GVkK3MP" from zhipuai import ZhipuAI client = ZhipuAI(api_key=api_key) completion = client.chat.completions.create( model="glm-4", # 填写需要调用的模型名称 messages=messages, # stream=True ) print("completion:",completion)
# print("BB:",completion.choices[0].message.content )
import re
code_pattern = r'```python[\s\S]+?```' code_match = re.search(code_pattern, completion.choices[0].message.content)
# 提取代码块 code_block = code_match.group(0) if code_match else "No code block found"
print("code_block:",code_block) cleaned_code = remove_code_fences(code_block) print("cleaned_code:", cleaned_code) with open('generate_combinations.py', 'w') as f: f.write(cleaned_code) # # 保存代码块为文件 # file_path = '/mnt/e/Base/pythonLearning/LLM/gradio_task1/code_block.py' # with open(file_path, 'w') as file: # file.write(code_block)
# 运行代码块 import os print("os.getcwd():",os.getcwd()) import subprocess CC = subprocess.run(['python','/mnt/e/Base/pythonLearning/LLM/gradio_task1/generate_combinations.py'], capture_output=True) print("CC:",CC) # 打印执行结果 print("Return code:", CC.returncode) print("Standard Output:") print(CC.stdout) print("Standard Error:") print(CC.stderr)
# # 打印结果 # result = subprocess.getoutput('cat /mnt/e/Base/pythonLearning/LLM/gradio_task1/output.txt') # print("res:",result)
return completion.choices[0].message.content
if __name__ == '_main_test_': messages = [{"role": "user", "content": "你好,请介绍一下你自己"}] response = create_chat_response(messages) print("AA:",response) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164# import gradio as gr# from utils_test import llm_reply# from config_test import LLM_MODELS# import pandas as pd
# with gr.Blocks() as demo:# with gr.Row():# # 左侧对话栏# with gr.Column():# chatbot=gr.Chatbot(label="智能聊天机器人",placeholder="你好,请在这里输入你的问题")# user_input=gr.Textbox(label="输入对话框",placeholder="你好,请在这里输入你的问题")# with gr.Row():# user_submit = gr.Button("提交")# gr.Button("清除")# with gr.Column(): # gr.Dropdown(# choices=LLM_MODELS,# value=LLM_MODELS[0],# label="选择模型",# interactive=True# )# gr.Slider(label="Temperature")# gr.Slider(label="Max_tokens")# gr.Slider(label="Frequency penalty")# gr.Slider(label="Presence penalty")
# # 用户点击事件# user_submit.click(# fn=llm_reply,# inputs=[user_input],# outputs=[chatbot],# )
# demo.launch(share=True)###################################################################################### # import gradio as gr# from utils_test import llm_reply# from config_test import LLM_MODELS# import pandas as pd
# # 设置左侧输入框和右侧参数设置的比例# left_column_width = 8# right_column_width = 1
# with gr.Blocks() as demo:# with gr.Row():# # 左侧对话栏占据更大比例# with gr.Column(scale=left_column_width):# chatbot = gr.Chatbot(label="智能聊天机器人", placeholder="你好,请在这里输入你的问题")# # 右侧参数设置占据较小比例# with gr.Column(scale=right_column_width):# model_selector = gr.Dropdown(# choices=LLM_MODELS,# value=LLM_MODELS[0],# label="选择模型",# interactive=True# )# temperature_slider = gr.Slider(label="Temperature")# max_tokens_slider = gr.Slider(label="Max_tokens")# frequency_penalty_slider = gr.Slider(label="Frequency penalty")# presence_penalty_slider = gr.Slider(label="Presence penalty")# # user_input = gr.Textbox(label="输入对话框", placeholder="你好,请在这里输入你的问题")# # with gr.Row():# # user_submit = gr.Button("提交")# # clear_button = gr.Button("清除")# with gr.Row():# with gr.Column(scale=left_column_width+right_column_width):# user_input = gr.Textbox(label="输入对话框", placeholder="你好,请在这里输入你的问题")# with gr.Row():# user_submit = gr.Button("提交")# clear_button = gr.Button("清除")
# # 用户点击提交按钮事件# user_submit.click(# fn=llm_reply,# # inputs=[user_input, model_selector, temperature_slider, max_tokens_slider, frequency_penalty_slider, presence_penalty_slider],# inputs=[user_input],# outputs=[chatbot],# )
# # 清除对话框内容的事件# clear_button.click(# fn=lambda: None, # 清除按钮不需要实际的函数,只需要设置None即可# inputs=[user_input],# outputs=[chatbot], # 清除聊天机器人和输入框的内容# )
# # 启动Gradio应用,共享选项默认开启# demo.launch(share=True)
#############################################################################################################import gradio as gr# from utils_test import llm_replyfrom config_test import LLM_MODELS
# 设置左侧输入框和右侧参数设置的比例left_column_width = 8right_column_width = 0.5
from gpt_chat_handler_test import create_chat_response
def llm_reply(user_input):
messages = [{"role": "user", "content": user_input}] gpt_response=create_chat_response(messages) return[[user_input,gpt_response]]
with gr.Blocks() as demo: with gr.Row(): # 左侧对话栏占据更大比例 # with gr.Column(scale=left_column_width): chatbot = gr.Chatbot(label="智能聊天机器人", placeholder="你好,请在这里输入你的问题") # gr.Spacer() # # 右侧参数设置占据较小比例 # with gr.Column(scale=right_column_width): # model_selector = gr.Dropdown( # choices=LLM_MODELS, # value=LLM_MODELS[0], # label="选择模型", # interactive=True # ) # temperature_slider = gr.Slider(label="Temperature") # max_tokens_slider = gr.Slider(label="Max_tokens") # frequency_penalty_slider = gr.Slider(label="Frequency penalty") # presence_penalty_slider = gr.Slider(label="Presence penalty")
with gr.Row(): with gr.Column(scale=left_column_width + right_column_width): user_input = gr.Textbox( label="输入对话框", placeholder="你好,请在这里输入你的问题", lines=3, # 限制输入框的行数,从而限制高度 max_lines=6 # 确保输入框不会超过最大行数 ) with gr.Row(): user_submit = gr.Button("提交") clear_button = gr.Button("清除")
# 用户点击提交按钮事件 user_submit.click( fn=lambda x: (llm_reply(x), ""), # 在调用llm_reply后返回空字符串以清除输入框 inputs=[user_input], outputs=[chatbot, user_input], # 输出聊天机器人的内容,并清除输入框 )
# 清除对话框内容的事件 clear_button.click( fn=lambda: ("", ""), # 返回空字符串以清除聊天机器人和输入框的内容 inputs=[], outputs=[chatbot, user_input], )
# 启动Gradio应用,共享选项默认开启demo.launch(share=True)123456789from gpt_chat_handler_test import create_chat_response
def llm_reply(user_input):
messages = [{"role": "user", "content": user_input}] gpt_response=create_chat_response(messages) return[[user_input,gpt_response]]123name,output,flag,username,timestamp
,,,,2024-07-23 18:16:04.767210
,,,,2024-07-23 18:16:07.865944.gitignoreAdded+138
README.en.mdAdded+36
README.md+40-7
app1/code_block.pyAdded+51
app1/config_test.pyAdded+26
app1/generate_combinations.pyAdded+52
app1/gpt_chat_handler_test.pyAdded+102
app1/main_test.pyAdded+164
app1/res.xlsxAdded
app1/utils_test.pyAdded+9
flagged/log.csvAdded+3