code stringlengths 1 1.05M | repo_name stringlengths 6 83 | path stringlengths 3 242 | language stringclasses 222
values | license stringclasses 20
values | size int64 1 1.05M |
|---|---|---|---|---|---|
import math
def euclidean_distance(x1, x2):
if len(x1) != len(x2):
raise ValueError("两个样本必须具有相同的维度")
# 欧氏距离公式:sqrt(sum((x1_i - x2_i)^2))
return math.sqrt(sum((a - b) ** 2 for a, b in zip(x1, x2)))
def knn_classify(train_features, train_labels, test_sample, k):
# 输入合法性检查
if no... | 2301_80822435/machine-learning-course | assignment4/2班46.py | Python | mit | 2,916 |
import math
import operator
from collections import Counter
def euclidean_distance(point1, point2):
"""
计算两个点之间的欧几里得距离
"""
if len(point1) != len(point2):
raise ValueError("Points must have the same dimensions")
squared_distance = 0
for i in range(len(point1)):
squared_dista... | 2301_80822435/machine-learning-course | assignment4/2班47.py | Python | mit | 7,708 |
import math # 导入数学模块
def euclidean_distance(point1, point2): # 计算欧几里得距离
return math.sqrt(sum((a - b) ** 2 for a, b in zip(point1, point2))) # 计算两点间距离
def knn_predict(train_data, train_labels, test_point, k=3): # K近邻预测函数
distances = [] # 存储距离的列表
for i, train_point in enumerate(train_data): # 遍历训... | 2301_80822435/machine-learning-course | assignment4/2班49.py | Python | mit | 1,502 |
import math
def euclidean_distance(x1, x2):
"""
计算两个数据点之间的欧氏距离
参数:
x1, x2: 数据点(列表或元组)
返回:
欧氏距离
"""
return math.sqrt(sum((x1[i] - x2[i]) ** 2 for i in range(len(x1))))
def find_k_nearest_neighbors(x, X_train, k):
"""
找到数据点x的k个最近邻
参数:
x: 待查询的数... | 2301_80822435/machine-learning-course | assignment4/2班50.py | Python | mit | 2,698 |
"""
手动实现K近邻算法(K-Nearest Neighbors, KNN)
只使用Python标准库
"""
import math
def knn_predict(X_train, y_train, x_test, k=3, weighted=True):
"""
K近邻预测(分类)- 简洁版本
参数:
X_train: 训练特征 [[x1, x2, ...], ...]
y_train: 训练标签 [label1, label2, ...]
x_test: 测试点 [x1, x2, ...] 或测试点列表 [[x1, x2, ...], ... | 2301_80822435/machine-learning-course | assignment4/2班51.py | Python | mit | 4,267 |
import math
from collections import Counter # Counter 用来统计邻居标签出现次数
from typing import List # 为函数/变量添加类型提示,提高可读性和 IDE 支持
def euclidean_distance(a: List[float], b: List[float]) -> float:
"""
计算两条等长向量的欧氏距离。
"""
if len(a) != len(b):
raise ValueError("向量维度不一致")# 防止维度不匹配导致 zip 失真
return m... | 2301_80822435/machine-learning-course | assignment4/2班54.py | Python | mit | 3,365 |
import numpy as np
from collections import Counter
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
class KNearestNeighbors:
def __init__(self, k=3):
self.k = k
self.X_train = None
self.y_train = None
def fit(self, X, y):... | 2301_80822435/machine-learning-course | assignment4/2班55.py | Python | mit | 3,357 |
import math
class KNN:
def __init__(self, k=3, task='classification'):
self.k = k
self.task = task
self.X_train = None
self.y_train = None
def fit(self, X, y):
self.X_train = X
self.y_train = y
return self
def _euclidean_distance(self, a, b):
... | 2301_80822435/machine-learning-course | assignment4/2班56.py | Python | mit | 3,610 |
import numpy as np
from collections import Counter
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
class KNN:
def __init__(self, k=3):
self.k = k
self.X_train = None
self.y_train = None
def fit(self, X, y):
... | 2301_80822435/machine-learning-course | assignment4/2班57.py | Python | mit | 3,930 |
import numpy as np
from collections import Counter
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score, classification_report
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'... | 2301_80822435/machine-learning-course | assignment4/2班59.py | Python | mit | 6,382 |
import numpy as np
from collections import Counter
class KNN:
def __init__(self, k=3):
"""初始化KNN模型,指定近邻数量k"""
self.k = k
self.X_train = None # 训练特征
self.y_train = None # 训练标签
def fit(self, X, y):
"""训练模型(KNN是惰性学习,仅存储训练数据)"""
self.X_train = X
self.y_tra... | 2301_80822435/machine-learning-course | assignment4/2班61.py | Python | mit | 1,851 |
import math
import heapq
def euclidean_distance(x1, x2):
if len(x1) != len(x2):
raise ValueError("两个样本的维度必须一致")
dist_sq = 0.0
for a, b in zip(x1, x2):
dist_sq += (a - b) ** 2
return math.sqrt(dist_sq)
def knn_classify(train_data, train_labels, x, k=3, distance_func=euclidean_distance):... | 2301_80822435/machine-learning-course | assignment4/2班63.py | Python | mit | 3,818 |
import numpy as np
from collections import Counter
class SimpleKNN:
def __init__(self, k=3):
self.k = k
self.X_train = None
self.y_train = None
# 计算欧氏距离
def _distance(self, x1, x2):
return np.sqrt(np.sum((x1 - x2) ** 2, axis=1))
# 训练
def fit(self, X_train, y_trai... | 2301_80822435/machine-learning-course | assignment4/2班64.py | Python | mit | 1,095 |
import math
from collections import Counter
def euclidean_distance(x1, x2):
"""
计算两个向量之间的欧几里得距离。
"""
distance = 0.0
for a, b in zip(x1, x2):
distance += (a - b) ** 2
return math.sqrt(distance)
class KNN:
def __init__(self, k=3, task_type='classification'):
"""
初始化 K... | 2301_80822435/machine-learning-course | assignment4/2班65.py | Python | mit | 2,674 |
import numpy as np
import matplotlib.pyplot as plt
from collections import Counter
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
class KNN:
def __init__(self, k=3, task='classification', label_num=None):
self.... | 2301_80822435/machine-learning-course | assignment4/2班66.py | Python | mit | 8,271 |
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
def distance(a, b):
return np.sqrt(np.sum((a - b) ** 2))
class KNN:
def __init__(self, k, label_num):
self.k = k
self.label_num = label_num
def fit(self, x_train, y_train):
self.x_tra... | 2301_80822435/machine-learning-course | assignment4/2班68.py | Python | mit | 2,512 |
import numpy as np
import matplotlib
matplotlib.use('TkAgg') # 兼容 PyCharm 绘图后端
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# 解决中文乱码
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams... | 2301_80822435/machine-learning-course | assignment4/2班70.py | Python | mit | 3,109 |
import math
import random
# ================================
# 1. 计算两点欧氏距离
# ================================
def euclidean_distance(x1, x2):
distance = 0
for i in range(len(x1)):
distance += (x1[i] - x2[i]) ** 2
return math.sqrt(distance)
# ================================
# 2. KNN 分... | 2301_80822435/machine-learning-course | assignmnet4/2班58.py | Python | mit | 2,143 |
import os
import sys
import binascii
import struct
import zlib
import itertools
import re
from collections import defaultdict
from PIL import Image
from PySide6.QtWidgets import (
QMainWindow,
QWidget,
QVBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QFileDialog,
QTextEdit,
... | 2301_80905479/123 | run_GUL.py | Python | unknown | 20,600 |
<script>
export default {
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
onError() {
console.log();
}
}
</script>
<style>
/*每个页面公共css */
@import 'lib/smart.css';
</style>
| 2301_80750063/SmartUI_lwh050 | App.vue | Vue | unknown | 317 |
<template>
<view class="cardstyle" :style="{'background-color': bgColor}">
<slot name="header"></slot>
<!-- 标题区域 -->
<view class="titlebox">
<!-- 模式2和3显示图片 -->
<view class="imgbox" v-if="mode === 2 || mode === 3">
<image :src="showImage" @error="handleImageException" mode="aspectFill"></image>
</... | 2301_80750063/SmartUI_lwh050 | components/CardViewText.vue | Vue | unknown | 4,863 |
<template>
<view class="content">
<text style="font-size: 50rpx ;">子组件A</text>
<view>
<text>父组件传进来的值:</text>
<text style="font-weight: bold;color:red">{{intent}}</text>
</view>
<button type="primary" @click="sendData()">传值给B组件</button>
</view>
</template>
<script>
export default {
name:"comA",
pro... | 2301_80750063/SmartUI_lwh050 | components/comA.vue | Vue | unknown | 603 |
<template>
<view class="content">
<view class="title">
子组件B
</view>
<view>
ComA组件传进来的值:
<text class="intent-text-box">{{result}}</text>
</view>
<view style="margin: 10rpx">
<text>回传值:</text>
<input type="text" :value="callBackValue" style="color: yellow;" />
<button @click="sendOutside()" s... | 2301_80750063/SmartUI_lwh050 | components/comB.vue | Vue | unknown | 688 |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<script>
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)'))
document.write(
'<meta name="viewport" content="width=device-wi... | 2301_80750063/SmartUI_lwh050 | index.html | HTML | unknown | 675 |
.smart-container{
padding: 15rpx;
background-color: #CEFFCE;
}
.smart-panel{
margin-bottom: 12px;
}
.smart-panel-title{
background-color: #f1f1f1;
font-size: 18px;
font-weight: normal;
padding: 5px;
flex-direction: row;
}
.smart-panel-h{
background-color: #ffffff;
flex-direction: row;
align-items: center;
p... | 2301_80750063/SmartUI_lwh050 | lib/smart.css | CSS | unknown | 2,659 |
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
... | 2301_80750063/SmartUI_lwh050 | main.js | JavaScript | unknown | 352 |
<template>
<view>
<view>
<image :src="iconFilePath" mode="aspectFit"></image>
</view>
<button @click="downloadImage" :disabled="downloading">
{{ downloading ? '下载中...' : '下载图片' }}
</button>
<button @click="previewImage" :disabled="!iconFilePath">
预览图片
</button>
</view>
</template>
<script>... | 2301_80750063/SmartUI_lwh050 | pages/APIpages/DownloadImages/DownloadImages.vue | Vue | unknown | 1,278 |
<template>
<view style="padding-top:100rpx;">
<view class="text-area">
<text>输入值:</text>
<input type="text" v-model="title" style="color: red;" />
</view>
<view class="text-area">
<text>回传值:</text>
<input type="text" :value="callBackValue" style="color: yellow;" />
</view>
<comA :itent="title"></... | 2301_80750063/SmartUI_lwh050 | pages/APIpages/IntentPage/IntentPage.vue | Vue | unknown | 940 |
<template>
<view>
<button @click="onLog()">concle.log</button>
</view>
</template>
<script>
export default {
data() {
return {
title:'打印日志'
}
},
methods: {
onLog(){
console.log('-----this.title: ',this.title);
}
}
}
</script>
<style>
</style>
| 2301_80750063/SmartUI_lwh050 | pages/APIpages/LogPage/LogPage.vue | Vue | unknown | 293 |
<template>
<view>
<!-- 天气信息显示区域 -->
<view v-if="weatherData">
<!-- 城市信息 -->
<view>
<text>城市: {{ weatherData.cityInfo.city }}</text>
</view>
<!-- 明天天气预报 -->
<view>
<text>明天天气预报</text>
<view>
<text>日期: {{ tomorrowData.ymd }}</text>
<text>星期: {{ tomorrowData.week }}</text>
... | 2301_80750063/SmartUI_lwh050 | pages/APIpages/Tianqiyubao/Tianqiyubao.vue | Vue | unknown | 1,718 |
<template>
<view>
<button @click="onSetTimeCall">单次定时器setTimeout</button>
<button @click="onSetTimeCallxy(name,password)">带参数setTimeout</button>
<button @click="onTimeoutClear(name,password)">取消</button>
</view>
</template>
<script>
export default {
data() {
return {
name:"lwh",
password:'666',
... | 2301_80750063/SmartUI_lwh050 | pages/APIpages/TimerPage/TimerPage.vue | Vue | unknown | 883 |
<template>
<view style="text-align: center;">
<view style="margin-top: 100px;">
<image :src="iconFilePath" @click="updateImage()" mode="aspectFill"></image>
</view>
</view>
</template>
<script>
export default {
data() {
return {
iconFilePath: "/static/logo.png"
}
},
methods: {
updateImage(... | 2301_80750063/SmartUI_lwh050 | pages/APIpages/imageyulan/imageyulan.vue | Vue | unknown | 689 |
<template>
<view>
<button>setStorage</button>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
onFunCall(){
name = uni.getStorageSync("userName");
pwd="ssss";
}
}
}
</script>
<style>
</style>
| 2301_80750063/SmartUI_lwh050 | pages/StoragePage/StoragePage.vue | Vue | unknown | 265 |
<template>
<view>
<page-head title="button,按钮"></page-head>
<view class="smart-padding-wrap">
<!-- 主操作按钮 -->
<button type="primary">页面主操作 normal</button>
<button type="primary" :loading="true">页面主操作 loading</button>
<button type="primary" disabled="false">页面主操作 disabled</button>
... | 2301_80750063/SmartUI_lwh050 | pages/components/button/button.vue | Vue | unknown | 1,517 |
<template>
<view>
<view class="smart-page-head">
<view class="smart-page-head-title">checkbox,多选按钮</view>
</view>
<view class="smart-padding-wrap">
<view class="item">
<checkbox checked="true"></checkbox>
选中
<checkbox></checkbox>
未选中
</view>
<view cl... | 2301_80750063/SmartUI_lwh050 | pages/components/checkbox/checkbox.vue | Vue | unknown | 1,436 |
<template>
<view>
<view class="smart-page-head">
<view class="smart-page-head-title">input,输入框</view>
</view>
<view class="smart-padding-wrap">
<view class="item">可自动获取焦点的</view>
<view><input class="smart-input" focus="true" placeholder="自动获取焦点" /></view>
<view>右下角显示搜索</view>
... | 2301_80750063/SmartUI_lwh050 | pages/components/input/input.vue | Vue | unknown | 3,115 |
<template>
<view>
<page-head :title='title'></page-head>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
| 2301_80750063/SmartUI_lwh050 | pages/components/navigator/navigate/navigate.vue | Vue | unknown | 200 |
<template>
<view>
<view class="smart-panel-head">
<view class="smart-panel-head-title">navigator,链接</view>
</view>
<view class="smart-padding-wrap">
<navigator url="/pages/newpage/newpage" hover-class="navigator-hover">
<button type="default">跳转到新页面</button>
</navigator>
<n... | 2301_80750063/SmartUI_lwh050 | pages/components/navigator/navigator.vue | Vue | unknown | 1,020 |
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
| 2301_80750063/SmartUI_lwh050 | pages/components/navigator/redirect/redirect.vue | Vue | unknown | 162 |
<template>
<view>
<!--顶部区域-->
<view class="smart-page-head">
<view class="smart-panel-head-title">scroll-view视图</view>
</view>
<view class="smart-padding-wrap">
<view class="smart-text">可视滚动视图区域.</view>
<view> vertical scroll 纵向滚动</view>
<view>
<scroll-view class="scroll-y" scroll-y="true">
... | 2301_80750063/SmartUI_lwh050 | pages/components/scroll-view/scroll-view.vue | Vue | unknown | 1,051 |
<template>
<view>
<!--顶部区域-->
<view class="smart-page-head">
<view class="smart-panel-head-title">swiper 滑块视图</view>
</view>
<view class="smart-padding-wrap">
<swiper circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
<swiper-item><view class="swiper-it... | 2301_80750063/SmartUI_lwh050 | pages/components/swiper/swiper.vue | Vue | unknown | 778 |
<template>
<view>
<view class="smart-panel-head">
<view class="smart-panel-head-title">text文本文件</view>
</view>
<view class="smart-padding-wrap">
<view class="text-box" scroll-y="true">
<text>{{ texts }}</text>
</view>
<button type="primary">add line</button>
<button type="warn">remove line</button>
<... | 2301_80750063/SmartUI_lwh050 | pages/components/text/text.vue | Vue | unknown | 1,435 |
<template>
<view>
<!--顶部区域-->
<view class="smart-panel-head">
<view class="smart-panel-head-title">View视图</view>
</view>
<!--主体部分-->
<view class="smart-padding-wrap">
<view>flex-direction:row 横向布局</view>
</view>
<view class="smart-flex smart-row">
<view class="flex-item smart-bg-blue">A</view>
... | 2301_80750063/SmartUI_lwh050 | pages/components/view/view.vue | Vue | unknown | 3,050 |
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
}
}
</script>
<s... | 2301_80750063/SmartUI_lwh050 | pages/index/index.vue | Vue | unknown | 696 |
<template>
<view class="login-container">
<view class="login-box">
<text class="login-title">登录</text>
<view class="input-item">
<input class="input-field" type="text" placeholder="请输入用户名" v-model="username" />
</view>
<view class="input-item">
<input class="input-field" ty... | 2301_80750063/SmartUI_lwh050 | pages/login/login.vue | Vue | unknown | 2,419 |
<template>
<view class="register-container">
<view class="register-box">
<text class="register-title">注册</text>
<view class="input-item">
<input type="text" placeholder="请输入用户名" v-model="username" />
</view>
<view class="input-item">
<input type="password" placeholder="请输入密... | 2301_80750063/SmartUI_lwh050 | pages/regist/regist.vue | Vue | unknown | 2,711 |
<template>
<view class="news-container">
<!-- 新增功能1: 选择图片并预览 -->
<view class="function-section">
<view class="section-title">作业功能一:选择本机图片并预览</view>
<view class="function-card">
<text class="function-title">3.1 选择图片 uni.chooseImage(OBJECT)</text>
<view class="function-description">
<text>使用uni.c... | 2301_80750063/SmartUI_lwh050 | pages/tabBar/CardViewPage/CardViewPage.vue | Vue | unknown | 7,424 |
<template>
<view>
<navigator url="/pages/APIpages/LogPage/LogPage">
<button>打印日志</button>
</navigator>
<navigator url="/pages/APIpages/TimerPage/TimerPage">
<button>计时器</button>
</navigator>
<navigator><button @click="goStotage">数据缓存</button></navigator>
<navigator url="/pages/APIpages/imageyulan/ima... | 2301_80750063/SmartUI_lwh050 | pages/tabBar/api/api.vue | Vue | unknown | 1,039 |
<template>
<scroll-view scroll-y style="height: 100vh;">
<!-- 轮播图 -->
<view class="swiper-card">
<text class="title">泉州风光</text>
<swiper circular indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
<swiper-item v-for="(item, index) in swiperImages" :key="index">
... | 2301_80750063/SmartUI_lwh050 | pages/tabBar/case/CityDiscovery/CityDiscovery.vue | Vue | unknown | 6,266 |
<template>
<view>
<view class="smart-container">登录页与注册页</view>
<view @click="goDetailPage(('login'))">
<text space="emsp">  登录页</text>
</view>
<view class="smart-container">城市探索</view>
<view @click="goDetailPage2(('CityDiscovery'))">
<text space="emsp">  城市探索</text>
</view>
<vie... | 2301_80750063/SmartUI_lwh050 | pages/tabBar/case/case.vue | Vue | unknown | 1,148 |
<template>
<view class="content">
<image :class="className" src="/static/logo.png"></image>
<view class="text-area">
<text class="title" v-on:click="open">{{title}}</text>
</view>
<view>
<view>{{ number + 1 }}</view>
<view>{{ ok ? 'YES' : 'NO' }}</view>
<view>{{ message.split('').reverse().join(''... | 2301_80750063/SmartUI_lwh050 | pages/tabBar/grammar/grammar.vue | Vue | unknown | 3,410 |
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
| 2301_80750063/SmartUI_lwh050 | pages/tabBar/mine/mine.vue | Vue | unknown | 162 |
<template>
<view>
<view class="smart-container">1.容器</view>
<view @click="goDetailPage('view')">
<text space="emsp">  view视图</text>
</view>
<view @click="goDetailPage('scroll-view')">
<text space="emsp">  scroll-view视图</text>
</view>
<view @click="goDetailPage('swiper')">
<text... | 2301_80750063/SmartUI_lwh050 | pages/tabBar/tabcompage/tabcompage.vue | Vue | unknown | 1,828 |
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
| 2301_80750063/SmartUI_lwh050 | pages/tabBar/topic/topic.vue | Vue | unknown | 162 |
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
| 2301_80750063/SmartUI_lwh050 | pages/tabBar/video/video.vue | Vue | unknown | 162 |
uni.addInterceptor({
returnValue (res) {
if (!(!!res && (typeof res === "object" || typeof res === "function") && typeof res.then === "function")) {
return res;
}
return new Promise((resolve, reject) => {
res.then((res) => {
if (!res) return resolve(res)
return res[0] ? reject... | 2301_80750063/SmartUI_lwh050 | uni.promisify.adaptor.js | JavaScript | unknown | 373 |
/**
* 这里是uni-app内置的常用样式变量
*
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
*
*/
/**
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
*
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
*/
/* ... | 2301_80750063/SmartUI_lwh050 | uni.scss | SCSS | unknown | 2,217 |
# -*- coding: utf-8 -*-
"""
FastMCP 快速入门示例。
首先,请切换到 `examples/snippets/clients` 目录,然后运行以下命令来启动服务器:
uv run server fastmcp_quickstart stdio
"""
# 从 mcp.server.fastmcp 模块中导入 FastMCP 类,这是构建 MCP 服务器的核心。
from mcp.server.fastmcp import FastMCP
# 创建一个 MCP 服务器实例,并将其命名为 "Demo"。
# 这个名字会向连接到此服务器的 AI 客户端展示。
mcp = FastMCP("D... | 2301_80863610/undoom-sketch-mcp | main copy.py | Python | mit | 2,451 |
# -*- coding: utf-8 -*-
"""
图片素描化 MCP 服务器。
提供图片素描化功能的 MCP 服务器,可以将输入的图片转换为素描效果。
支持多种素描风格和批量处理功能。
"""
# 导入必要的库
import cv2
import numpy as np
import os
import base64
import glob
from pathlib import Path
from mcp.server.fastmcp import FastMCP
# 创建一个 MCP 服务器实例,并将其命名为 "SketchConverter"。
# 这个名字会向连接到此服务器的 AI 客户端展示。
mcp = F... | 2301_80863610/undoom-sketch-mcp | main.py | Python | mit | 11,461 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单的图片素描转换示例
直接调用本地的素描转换功能,无需MCP协议。
"""
import sys
import os
# 添加当前目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from undoom_sketch_mcp.server import convert_image_to_sketch, get_image_info
def main():
"""主函数 - 直接调用素描转换功能"""
... | 2301_80863610/undoom-sketch-mcp | simple_sketch_example.py | Python | mit | 1,996 |
"""
Undoom Sketch MCP - 图片素描化转换服务器
一个基于 MCP (Model Context Protocol) 的图片素描化服务器,
可以将普通图片转换为素描效果,支持多种风格和批量处理。
"""
__version__ = "0.1.4"
__author__ = "Undoom"
__email__ = "kaikaihuhu666@163.com"
from .server import main
__all__ = ["main"] | 2301_80863610/undoom-sketch-mcp | undoom_sketch_mcp/__init__.py | Python | mit | 341 |
#!/usr/bin/env python3
"""
Undoom Sketch MCP Server - 主入口点
通过 python -m undoom_sketch_mcp 启动服务器
"""
from .server import main
if __name__ == "__main__":
main() | 2301_80863610/undoom-sketch-mcp | undoom_sketch_mcp/__main__.py | Python | mit | 187 |
# -*- coding: utf-8 -*-
"""
图片素描化 MCP 服务器。
提供图片素描化功能的 MCP 服务器,可以将输入的图片转换为素描效果。
支持多种素描风格和批量处理功能。
"""
# 导入必要的库
import cv2
import numpy as np
import os
import base64
import glob
from pathlib import Path
from mcp.server.fastmcp import FastMCP
# 创建一个 MCP 服务器实例,并将其命名为 "SketchConverter"。
# 这个名字会向连接到此服务器的 AI 客户端展示。
mcp = F... | 2301_80863610/undoom-sketch-mcp | undoom_sketch_mcp/server.py | Python | mit | 11,528 |
# Written in 2016-2017, 2021 by Henrik Steffen Gaßmann henrik@gassmann.onl
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
#
# You should have recei... | 2301_81045437/base64 | CMakeLists.txt | CMake | bsd | 10,403 |
CFLAGS += -std=c99 -O3 -Wall -Wextra -pedantic -DBASE64_STATIC_DEFINE
# Set OBJCOPY if not defined by environment:
OBJCOPY ?= objcopy
OBJS = \
lib/arch/avx512/codec.o \
lib/arch/avx2/codec.o \
lib/arch/generic/codec.o \
lib/arch/neon32/codec.o \
lib/arch/neon64/codec.o \
lib/arch/ssse3/codec.o \
lib/arc... | 2301_81045437/base64 | Makefile | Makefile | bsd | 2,620 |
# Written in 2017 by Henrik Steffen Gaßmann henrik@gassmann.onl
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
#
# You should have received a copy ... | 2301_81045437/base64 | cmake/Modules/TargetArch.cmake | CMake | bsd | 1,167 |
# Written in 2016-2017 by Henrik Steffen Gaßmann henrik@gassmann.onl
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
#
# You should have received a ... | 2301_81045437/base64 | cmake/Modules/TargetSIMDInstructionSet.cmake | CMake | bsd | 1,458 |
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/base64-targets.cmake")
check_required_components(base64)
| 2301_81045437/base64 | cmake/base64-config.cmake.in | CMake | bsd | 109 |
// Written in 2017 by Henrik Steffen Gaßmann henrik@gassmann.onl
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to the
// public domain worldwide. This software is distributed without any warranty.
//
// You should have received ... | 2301_81045437/base64 | cmake/test-arch.c | C | bsd | 903 |
#ifndef LIBBASE64_H
#define LIBBASE64_H
#include <stddef.h> /* size_t */
#if defined(_WIN32) || defined(__CYGWIN__)
#define BASE64_SYMBOL_IMPORT __declspec(dllimport)
#define BASE64_SYMBOL_EXPORT __declspec(dllexport)
#define BASE64_SYMBOL_PRIVATE
#elif __GNUC__ >= 4
#define BASE64_SYMBOL_IMPORT __attribute__ ((v... | 2301_81045437/base64 | include/libbase64.h | C | bsd | 4,789 |
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include "../../../include/libbase64.h"
#include "../../tables/tables.h"
#include "../../codecs.h"
#include "config.h"
#include "../../env.h"
#if HAVE_AVX
#include <immintrin.h>
// Only enable inline assembly on supported compilers and on 64-bit CPUs.
#ifnd... | 2301_81045437/base64 | lib/arch/avx/codec.c | C | bsd | 1,504 |
// Apologies in advance for combining the preprocessor with inline assembly,
// two notoriously gnarly parts of C, but it was necessary to avoid a lot of
// code repetition. The preprocessor is used to template large sections of
// inline assembly that differ only in the registers used. If the code was
// written out b... | 2301_81045437/base64 | lib/arch/avx/enc_loop_asm.c | C | bsd | 9,314 |
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include "../../../include/libbase64.h"
#include "../../tables/tables.h"
#include "../../codecs.h"
#include "config.h"
#include "../../env.h"
#if HAVE_AVX2
#include <immintrin.h>
// Only enable inline assembly on supported compilers and on 64-bit CPUs.
#ifn... | 2301_81045437/base64 | lib/arch/avx2/codec.c | C | bsd | 1,199 |
static BASE64_FORCE_INLINE int
dec_loop_avx2_inner (const uint8_t **s, uint8_t **o, size_t *rounds)
{
const __m256i lut_lo = _mm256_setr_epi8(
0x15, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x13, 0x1A, 0x1B, 0x1B, 0x1B, 0x1A,
0x15, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x13, 0x1A, ... | 2301_81045437/base64 | lib/arch/avx2/dec_loop.c | C | bsd | 3,229 |
static BASE64_FORCE_INLINE __m256i
dec_reshuffle (const __m256i in)
{
// in, lower lane, bits, upper case are most significant bits, lower
// case are least significant bits:
// 00llllll 00kkkkLL 00jjKKKK 00JJJJJJ
// 00iiiiii 00hhhhII 00ggHHHH 00GGGGGG
// 00ffffff 00eeeeFF 00ddEEEE 00DDDDDD
// 00cccccc 00bbbbCC 0... | 2301_81045437/base64 | lib/arch/avx2/dec_reshuffle.c | C | bsd | 1,304 |
static BASE64_FORCE_INLINE void
enc_loop_avx2_inner_first (const uint8_t **s, uint8_t **o)
{
// First load is done at s - 0 to not get a segfault:
__m256i src = _mm256_loadu_si256((__m256i *) *s);
// Shift by 4 bytes, as required by enc_reshuffle:
src = _mm256_permutevar8x32_epi32(src, _mm256_setr_epi32(0, 0, 1, 2... | 2301_81045437/base64 | lib/arch/avx2/enc_loop.c | C | bsd | 2,293 |
// Apologies in advance for combining the preprocessor with inline assembly,
// two notoriously gnarly parts of C, but it was necessary to avoid a lot of
// code repetition. The preprocessor is used to template large sections of
// inline assembly that differ only in the registers used. If the code was
// written out b... | 2301_81045437/base64 | lib/arch/avx2/enc_loop_asm.c | C | bsd | 10,453 |
static BASE64_FORCE_INLINE __m256i
enc_reshuffle (const __m256i input)
{
// Translation of the SSSE3 reshuffling algorithm to AVX2. This one
// works with shifted (4 bytes) input in order to be able to work
// efficiently in the two 128-bit lanes.
// Input, bytes MSB to LSB:
// 0 0 0 0 x w v u t s r q p o n m
//... | 2301_81045437/base64 | lib/arch/avx2/enc_reshuffle.c | C | bsd | 2,714 |
static BASE64_FORCE_INLINE __m256i
enc_translate (const __m256i in)
{
// A lookup table containing the absolute offsets for all ranges:
const __m256i lut = _mm256_setr_epi8(
65, 71, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -19, -16, 0, 0,
65, 71, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -19, -16, 0, 0);
// Transl... | 2301_81045437/base64 | lib/arch/avx2/enc_translate.c | C | bsd | 1,251 |
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include "../../../include/libbase64.h"
#include "../../tables/tables.h"
#include "../../codecs.h"
#include "config.h"
#include "../../env.h"
#if HAVE_AVX512
#include <immintrin.h>
#include "../avx2/dec_reshuffle.c"
#include "../avx2/dec_loop.c"
#include "e... | 2301_81045437/base64 | lib/arch/avx512/codec.c | C | bsd | 940 |
static BASE64_FORCE_INLINE void
enc_loop_avx512_inner (const uint8_t **s, uint8_t **o)
{
// Load input.
__m512i src = _mm512_loadu_si512((__m512i *) *s);
// Reshuffle, translate, store.
src = enc_reshuffle_translate(src);
_mm512_storeu_si512((__m512i *) *o, src);
*s += 48;
*o += 64;
}
static inline void
enc_l... | 2301_81045437/base64 | lib/arch/avx512/enc_loop.c | C | bsd | 1,506 |
// AVX512 algorithm is based on permutevar and multishift. The code is based on
// https://github.com/WojciechMula/base64simd which is under BSD-2 license.
static BASE64_FORCE_INLINE __m512i
enc_reshuffle_translate (const __m512i input)
{
// 32-bit input
// [ 0 0 0 0 0 0 0 0|c1 c0 d5 d4 d3 d2 d1 d0|
// b3 b... | 2301_81045437/base64 | lib/arch/avx512/enc_reshuffle_translate.c | C | bsd | 2,278 |
static BASE64_FORCE_INLINE int
dec_loop_generic_32_inner (const uint8_t **s, uint8_t **o, size_t *rounds)
{
const uint32_t str
= base64_table_dec_32bit_d0[(*s)[0]]
| base64_table_dec_32bit_d1[(*s)[1]]
| base64_table_dec_32bit_d2[(*s)[2]]
| base64_table_dec_32bit_d3[(*s)[3]];
#if BASE64_LITTLE_ENDIAN
// LUTs... | 2301_81045437/base64 | lib/arch/generic/32/dec_loop.c | C | bsd | 2,218 |
static BASE64_FORCE_INLINE void
enc_loop_generic_32_inner (const uint8_t **s, uint8_t **o)
{
uint32_t src;
// Load input:
memcpy(&src, *s, sizeof (src));
// Reorder to 32-bit big-endian, if not already in that format. The
// workset must be in big-endian, otherwise the shifted bits do not
// carry over properly... | 2301_81045437/base64 | lib/arch/generic/32/enc_loop.c | C | bsd | 1,932 |
static BASE64_FORCE_INLINE void
enc_loop_generic_64_inner (const uint8_t **s, uint8_t **o)
{
uint64_t src;
// Load input:
memcpy(&src, *s, sizeof (src));
// Reorder to 64-bit big-endian, if not already in that format. The
// workset must be in big-endian, otherwise the shifted bits do not
// carry over properly... | 2301_81045437/base64 | lib/arch/generic/64/enc_loop.c | C | bsd | 2,128 |
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "../../../include/libbase64.h"
#include "../../tables/tables.h"
#include "../../codecs.h"
#include "config.h"
#include "../../env.h"
#if BASE64_WORDSIZE == 32
# include "32/enc_loop.c"
#elif BASE64_WORDSIZE == 64
# include "64/enc_loop.c"
#endif
... | 2301_81045437/base64 | lib/arch/generic/codec.c | C | bsd | 807 |
int ret = 0;
const uint8_t *s = (const uint8_t *) src;
uint8_t *o = (uint8_t *) out;
uint8_t q;
// Use local temporaries to avoid cache thrashing:
size_t olen = 0;
size_t slen = srclen;
struct base64_state st;
st.eof = state->eof;
st.bytes = state->bytes;
st.carry = state->carry;
// If we previously saw an EOF or an ... | 2301_81045437/base64 | lib/arch/generic/dec_head.c | C | bsd | 791 |
if (slen-- == 0) {
ret = 1;
break;
}
if ((q = base64_table_dec_8bit[*s++]) >= 254) {
st.eof = BASE64_EOF;
// Treat character '=' as invalid for byte 0:
break;
}
st.carry = q << 2;
st.bytes++;
// Deliberate fallthrough:
BASE64_FALLTHROUGH
case 1: if (slen-- == 0) {
ret = 1;
break;... | 2301_81045437/base64 | lib/arch/generic/dec_tail.c | C | bsd | 1,774 |
// Assume that *out is large enough to contain the output.
// Theoretically it should be 4/3 the length of src.
const uint8_t *s = (const uint8_t *) src;
uint8_t *o = (uint8_t *) out;
// Use local temporaries to avoid cache thrashing:
size_t olen = 0;
size_t slen = srclen;
struct base64_state st;
st.bytes = state->byt... | 2301_81045437/base64 | lib/arch/generic/enc_head.c | C | bsd | 585 |
if (slen-- == 0) {
break;
}
*o++ = base64_table_enc_6bit[*s >> 2];
st.carry = (*s++ << 4) & 0x30;
st.bytes++;
olen += 1;
// Deliberate fallthrough:
BASE64_FALLTHROUGH
case 1: if (slen-- == 0) {
break;
}
*o++ = base64_table_enc_6bit[st.carry | (*s >> 4)];
st.carry = (*s++ << 2) & 0x3C;
s... | 2301_81045437/base64 | lib/arch/generic/enc_tail.c | C | bsd | 637 |
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "../../../include/libbase64.h"
#include "../../tables/tables.h"
#include "../../codecs.h"
#include "config.h"
#include "../../env.h"
#ifdef __arm__
# if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && HAVE_NEON32
# define BASE64_USE_NEON32
# ... | 2301_81045437/base64 | lib/arch/neon32/codec.c | C | bsd | 2,001 |
static BASE64_FORCE_INLINE int
is_nonzero (const uint8x16_t v)
{
uint64_t u64;
const uint64x2_t v64 = vreinterpretq_u64_u8(v);
const uint32x2_t v32 = vqmovn_u64(v64);
vst1_u64(&u64, vreinterpret_u64_u32(v32));
return u64 != 0;
}
static BASE64_FORCE_INLINE uint8x16_t
delta_lookup (const uint8x16_t v)
{
const uin... | 2301_81045437/base64 | lib/arch/neon32/dec_loop.c | C | bsd | 2,906 |
#ifdef BASE64_NEON32_USE_ASM
static BASE64_FORCE_INLINE void
enc_loop_neon32_inner_asm (const uint8_t **s, uint8_t **o)
{
// This function duplicates the functionality of enc_loop_neon32_inner,
// but entirely with inline assembly. This gives a significant speedup
// over using NEON intrinsics, which do not always g... | 2301_81045437/base64 | lib/arch/neon32/enc_loop.c | C | bsd | 4,655 |
static BASE64_FORCE_INLINE uint8x16x4_t
enc_reshuffle (uint8x16x3_t in)
{
uint8x16x4_t out;
// Input:
// in[0] = a7 a6 a5 a4 a3 a2 a1 a0
// in[1] = b7 b6 b5 b4 b3 b2 b1 b0
// in[2] = c7 c6 c5 c4 c3 c2 c1 c0
// Output:
// out[0] = 00 00 a7 a6 a5 a4 a3 a2
// out[1] = 00 00 a1 a0 b7 b6 b5 b4
// out[2] = 00 0... | 2301_81045437/base64 | lib/arch/neon32/enc_reshuffle.c | C | bsd | 982 |
static BASE64_FORCE_INLINE uint8x16x4_t
enc_translate (const uint8x16x4_t in)
{
// A lookup table containing the absolute offsets for all ranges:
const uint8x16_t lut = {
65U, 71U, 252U, 252U,
252U, 252U, 252U, 252U,
252U, 252U, 252U, 252U,
237U, 240U, 0U, 0U
};
const uint8x16_t offset = vdupq_n_u8(5... | 2301_81045437/base64 | lib/arch/neon32/enc_translate.c | C | bsd | 2,116 |
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "../../../include/libbase64.h"
#include "../../tables/tables.h"
#include "../../codecs.h"
#include "config.h"
#include "../../env.h"
#ifdef __aarch64__
# if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && HAVE_NEON64
# define BASE64_USE_NEON64... | 2301_81045437/base64 | lib/arch/neon64/codec.c | C | bsd | 2,350 |
// The input consists of five valid character sets in the Base64 alphabet,
// which we need to map back to the 6-bit values they represent.
// There are three ranges, two singles, and then there's the rest.
//
// # From To LUT Characters
// 1 [0..42] [255] #1 invalid input
// 2 [43] ... | 2301_81045437/base64 | lib/arch/neon64/dec_loop.c | C | bsd | 5,205 |
static BASE64_FORCE_INLINE void
enc_loop_neon64_inner (const uint8_t **s, uint8_t **o, const uint8x16x4_t tbl_enc)
{
// Load 48 bytes and deinterleave:
uint8x16x3_t src = vld3q_u8(*s);
// Divide bits of three input bytes over four output bytes:
uint8x16x4_t out = enc_reshuffle(src);
// The bits have now been shi... | 2301_81045437/base64 | lib/arch/neon64/enc_loop.c | C | bsd | 1,857 |
// Apologies in advance for combining the preprocessor with inline assembly,
// two notoriously gnarly parts of C, but it was necessary to avoid a lot of
// code repetition. The preprocessor is used to template large sections of
// inline assembly that differ only in the registers used. If the code was
// written out b... | 2301_81045437/base64 | lib/arch/neon64/enc_loop_asm.c | C | bsd | 5,617 |
static BASE64_FORCE_INLINE uint8x16x4_t
enc_reshuffle (const uint8x16x3_t in)
{
uint8x16x4_t out;
// Input:
// in[0] = a7 a6 a5 a4 a3 a2 a1 a0
// in[1] = b7 b6 b5 b4 b3 b2 b1 b0
// in[2] = c7 c6 c5 c4 c3 c2 c1 c0
// Output:
// out[0] = 00 00 a7 a6 a5 a4 a3 a2
// out[1] = 00 00 a1 a0 b7 b6 b5 b4
// out[2] ... | 2301_81045437/base64 | lib/arch/neon64/enc_reshuffle.c | C | bsd | 988 |