update
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
from itertools import combinations
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
# 钱币有且只有“花”“衡”“厉”三个种类。
|
||||
# 盒子里有三个种类的钱币若干枚,由用户输入每种钱币的数量box。
|
||||
# 通过排列组合原理计算:从盒子中任意取出pick枚钱币时,取出的钱币数量满足requirement的概率。
|
||||
# 函数输入:
|
||||
# box: (1, 2, 3) 分别是盒子中花、衡、厉三种钱的数量。
|
||||
# requirement: ((0, 3),(0, 3),(0, 3)),分别时掷出的钱中花、衡、厉三种钱的最少、最多数量。
|
||||
# pick: 3,从盒子中取出钱币的数量。
|
||||
|
||||
def calculate_probability(box, requirement, pick):
|
||||
total_coins = sum(box)
|
||||
if pick > total_coins:
|
||||
return 0.0
|
||||
|
||||
# 生成所有可能的组合
|
||||
coins = ['H'] * box[0] + ['E'] * box[1] + ['L'] * box[2]
|
||||
|
||||
valid_combinations = 0
|
||||
all_combinations = list(combinations(coins, pick))
|
||||
|
||||
for combo in all_combinations:
|
||||
count_H = combo.count('H')
|
||||
count_E = combo.count('E')
|
||||
count_L = combo.count('L')
|
||||
|
||||
if (requirement[0][0] <= count_H <= requirement[0][1] and
|
||||
requirement[1][0] <= count_E <= requirement[1][1] and
|
||||
requirement[2][0] <= count_L <= requirement[2][1]):
|
||||
valid_combinations += 1
|
||||
|
||||
probability = valid_combinations / len(all_combinations)
|
||||
return probability
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
if request.method == 'POST':
|
||||
box = tuple(map(int, request.form['box'].split(',')))
|
||||
requirement = tuple(tuple(map(int, req.split(','))) for req in request.form['requirement'].split(';'))
|
||||
pick = int(request.form['pick'])
|
||||
|
||||
probability = calculate_probability(box, requirement, pick)
|
||||
return jsonify({'probability': probability})
|
||||
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port=5001)
|
||||
|
||||
# Example usage:
|
||||
# if __name__ == "__main__":
|
||||
# box = (1, 4, 2)
|
||||
# requirement = ((0, 3), (0, 3), (1, 3))
|
||||
# pick = 3
|
||||
# print(calculate_probability(box, requirement, pick))
|
||||
@@ -0,0 +1,117 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>界园投币概率计算器</title>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 20px;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
input {
|
||||
margin-bottom: 10px;
|
||||
width: 80px;
|
||||
}
|
||||
#result {
|
||||
margin-top: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.title {
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>钱币概率计算器</h1>
|
||||
<form id="coin-form">
|
||||
<div class="title">钱盒中已有的钱币数量</div>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<div>
|
||||
<label for="box_hua">花钱:</label>
|
||||
<input type="number" id="box_hua" name="box_hua" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="box_heng">衡钱:</label>
|
||||
<input type="number" id="box_heng" name="box_heng" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="box_li">厉钱:</label>
|
||||
<input type="number" id="box_li" name="box_li" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="pick">掷出钱币的数量:</label>
|
||||
<input type="number" id="pick" name="pick" value="3">
|
||||
<br>
|
||||
|
||||
<div class="title">判定条件(没有可以不填)</div>
|
||||
<label for="req_hua_min">花钱:</label>
|
||||
<input type="number" id="req_hua_min" name="req_hua_min">
|
||||
<span>~</span>
|
||||
<input type="number" id="req_hua_max" name="req_hua_max">
|
||||
|
||||
<label for="req_heng_min">衡钱:</label>
|
||||
<input type="number" id="req_heng_min" name="req_heng_min">
|
||||
<span>~</span>
|
||||
<input type="number" id="req_heng_max" name="req_heng_max">
|
||||
|
||||
<label for="req_li_min">厉钱:</label>
|
||||
<input type="number" id="req_li_min" name="req_li_min">
|
||||
<span>~</span>
|
||||
<input type="number" id="req_li_max" name="req_li_max">
|
||||
|
||||
<br>
|
||||
|
||||
<button type="submit">计算概率</button>
|
||||
</form>
|
||||
|
||||
<div id="result"></div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#coin-form').on('submit', function(event) {
|
||||
event.preventDefault(); // 阻止表单默认提交行为
|
||||
|
||||
var box_hua = $('#box_hua').val();
|
||||
var box_heng = $('#box_heng').val();
|
||||
var box_li = $('#box_li').val();
|
||||
|
||||
var req_hua_min = $('#req_hua_min').val() || 0;
|
||||
var req_hua_max = $('#req_hua_max').val() || 99;
|
||||
var req_heng_min = $('#req_heng_min').val() || 0;
|
||||
var req_heng_max = $('#req_heng_max').val() || 99;
|
||||
var req_li_min = $('#req_li_min').val() || 0;
|
||||
var req_li_max = $('#req_li_max').val() || 99;
|
||||
|
||||
var pick = $('#pick').val();
|
||||
|
||||
var box = [box_hua, box_heng, box_li];
|
||||
var requirement = [[req_hua_min, req_hua_max], [req_heng_min, req_heng_max], [req_li_min, req_li_max]];
|
||||
|
||||
$.ajax({
|
||||
url: '/',
|
||||
type: 'POST',
|
||||
data: {
|
||||
box: box.join(','),
|
||||
requirement: requirement.map(req => req.join(',')).join(';'),
|
||||
pick: pick
|
||||
},
|
||||
success: function(response) {
|
||||
var probability = (response.probability * 100).toFixed(2); // 将概率转换为百分数并保留两位小数
|
||||
$('#result').text('概率: ' + probability + '%');
|
||||
},
|
||||
error: function(error) {
|
||||
$('#result').text('计算失败,请检查输入。');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,3 +8,37 @@ LLM = ChatOllama(model='qwen2.5:14b', api_key="1145141919810", base_url='http://
|
||||
tavily_key = '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'
|
||||
|
||||
gaode_key = '00fd082df2414f75c6efb64896819451'
|
||||
|
||||
#
|
||||
#
|
||||
# import requests
|
||||
#
|
||||
# url = 'http://192.168.195.158:61000/LLMProcessStream'
|
||||
# json = {
|
||||
# "conversation_id": "49fcf90889cb5538d6171cc5043537cd",
|
||||
# "model": "qwen2.5:14b",
|
||||
# "user_input": "Good day",
|
||||
# "require_voice": False,
|
||||
# "rag": False
|
||||
# }
|
||||
#
|
||||
# headers = {'Authorization': '9a504ac370734c811d107b2f634185b0', 'user': "armor"}
|
||||
# response = requests.post(url, json=json, headers=headers, stream=True)
|
||||
#
|
||||
# result_str = ''
|
||||
# flag = True
|
||||
# for i in response:
|
||||
# target = i.decode('utf-8')
|
||||
# if '<1json2>' not in target:
|
||||
# pass
|
||||
# else:
|
||||
# flag = False
|
||||
# if flag:
|
||||
# print(target, end='')
|
||||
# if not flag:
|
||||
# result_str += target
|
||||
# result_str = result_str.replace('<1json2>', '')
|
||||
# print('')
|
||||
# print(result_str)
|
||||
|
||||
|
||||
|
||||
@@ -185,6 +185,9 @@ if '__main__' == __name__:
|
||||
print(s)
|
||||
print('-'*80)
|
||||
|
||||
import datetime
|
||||
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import struct
|
||||
|
||||
def read_uint32(data, offset):
|
||||
return struct.unpack('>I', data[offset:offset+4])[0]
|
||||
|
||||
def patch_duration(data, box_type, new_duration_sec, start=0, end=None):
|
||||
if end is None:
|
||||
end = len(data)
|
||||
offset = start
|
||||
while offset < end:
|
||||
if offset + 8 > len(data):
|
||||
break
|
||||
size = read_uint32(data, offset)
|
||||
if size < 8:
|
||||
break
|
||||
typ = data[offset+4:offset+8]
|
||||
if typ == box_type:
|
||||
version = data[offset+8]
|
||||
if version == 0:
|
||||
timescale_offset = offset+20
|
||||
duration_offset = offset+24
|
||||
timescale = read_uint32(data, timescale_offset)
|
||||
# 如果 timescale 异常大,强制修正
|
||||
if timescale > 100000:
|
||||
print(f'{box_type.decode()} timescale异常({timescale}),强制设为1000')
|
||||
timescale = 1000
|
||||
data[timescale_offset:timescale_offset+4] = struct.pack('>I', timescale)
|
||||
new_duration = int(new_duration_sec * timescale)
|
||||
if not (0 <= new_duration <= 0xFFFFFFFF):
|
||||
print(f'{box_type.decode()} duration超出范围,使用最大值')
|
||||
new_duration = 0xFFFFFFFF
|
||||
data[duration_offset:duration_offset+4] = struct.pack('>I', new_duration)
|
||||
print(f'已修正{box_type.decode()} duration: {new_duration} (timescale={timescale})')
|
||||
else:
|
||||
print(f'{box_type.decode()} 暂不支持 version 1')
|
||||
# 递归 container box
|
||||
if typ in [b'moov', b'trak', b'mdia']:
|
||||
patch_duration(data, box_type, new_duration_sec, offset+8, offset+size)
|
||||
offset += size if size > 0 else 8
|
||||
|
||||
def fix_mp4_duration(file_path, output_path, new_duration_sec):
|
||||
with open(file_path, 'rb') as f:
|
||||
data = bytearray(f.read())
|
||||
for box in [b'mvhd', b'tkhd', b'mdhd']:
|
||||
patch_duration(data, box, new_duration_sec)
|
||||
with open(output_path, 'wb') as f:
|
||||
f.write(data)
|
||||
print('修复完成,请检查时长')
|
||||
|
||||
if __name__ == '__main__':
|
||||
fix_mp4_duration(
|
||||
r'C:\Users\26549\Downloads\Video\1.mp4',
|
||||
r'C:\Users\26549\Downloads\Video\1_fixed.mp4',
|
||||
7200
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
import whisper
|
||||
import os
|
||||
|
||||
# 加载Whisper模型(可选"base"、"small"、"medium"、"large")
|
||||
model = whisper.load_model("medium")
|
||||
|
||||
path = r'C:\Users\26549\OneDrive\工作\北电数智科技\EV\250701_1318.m4a'
|
||||
print(os.path.exists(path))
|
||||
|
||||
# 读取并转写m4a音频文件
|
||||
result = model.transcribe(audio=path, language="zh")
|
||||
|
||||
# 输出转写结果
|
||||
print(result["text"])
|
||||
print('done')
|
||||
Reference in New Issue
Block a user