当前位置: 首页 > news >正文

文生TikZ

目录

Qwen-GeoGebra-Coder-7B

文生TikZ

Qwen/Qwen3-0.6B 要单独下载


Qwen-GeoGebra-Coder-7B

from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from llama_cpp import Llama import uvicorn import re app = FastAPI() # Standard CORS setup for local web tools app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"] ) # Load the fine-tuned math model # Utilizing the full 16GB VRAM of the RTX 4060 Ti llm = Llama( model_path="/home/khurram/ai_models/math_dataset/math_viz_Q4_K_M.gguf", n_gpu_layers=-1, n_ctx=2048, n_batch=512, temperature=0.1 ) def clean_and_format_ggb(raw_text): """ Standardizes model coordinates and brackets for GeoGebra. Converts [Cylinder[<0,0,0>, <3,0,0>, <0,10,0>]] to Cylinder((0,0,0), (0,10,0), 3.0) """ # 1. Clean up bracket variations text = raw_text.replace("<", "(").replace(">", ")") # 2. Extract all coordinate sets (x,y,z) coords = re.findall(r"\((-?\d+\.?\d*,\s*-?\d+\.?\d*,\s*-?\d+\.?\d*)\)", text) if len(coords) >= 3: bottom_pt = f"({coords[0]})" top_pt = f"({coords[2]})" # Extract scalar radius from the middle point radius_match = re.findall(r"[-+]?\d*\.\d+|\d+", coords[1]) radius = next((abs(float(n)) for n in radius_match if float(n) != 0), 3.0) return f"Cylinder({bottom_pt}, {top_pt}, {radius})" # Fallback for simple Sphere or direct commands return text.replace("[", "").replace("]", "").replace("<", "(").replace(">", ")").strip() @app.post("/ask") async def ask_geo(data: dict): user_prompt = data.get("prompt", "") # Step 1: Request the "Thought" (Mathematical Reasoning) prompt = f"<|im_start|>user\n{user_prompt}<|im_end|>\n<|im_start|>thought\n" thought_output = llm(prompt, max_tokens=150, stop=["<|im_end|>"]) thought_text = thought_output["choices"][0]["text"].strip() # Step 2: Request the "Assistant" (GeoGebra Code) command_prompt = f"{prompt}{thought_text}<|im_end|>\n<|im_start|>assistant\n" command_output = llm(command_prompt, max_tokens=150, stop=["<|im_end|>"]) assistant_raw = command_output["choices"][0]["text"].strip() # Final string formatting for the GeoGebra Applet final_cmds = clean_and_format_ggb(assistant_raw) return { "commands": final_cmds, "thought": thought_text } if __name__ == "__main__": uvicorn.run(app, host="127.0.0.1", port=8000)

文生TikZ

环境安装:

pip install peft pip install transformers==5.14.1

Qwen/Qwen3-0.6B 要单独下载

import torch from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel BASE = "Qwen/Qwen3-0.6B" # match the adapter's base model REPO = "kyhe/qwen3-geotikz" # this Hub repo ADAPTER = "qwen3-pgf-geotikz" # subfolder for the v2 specialist tok = AutoTokenizer.from_pretrained(BASE) model = AutoModelForCausalLM.from_pretrained(BASE, dtype=torch.bfloat16) model = PeftModel.from_pretrained(model, REPO, subfolder=ADAPTER).eval() SYSTEM = ( "You are a geometry-to-TikZ compiler. Given a geometry scene described only through " "relationships and constraints (no explicit coordinates), you must derive the exact " "coordinates yourself and output a single valid TikZ/PGF figure that compiles and " "renders the described geometry. Output ONLY the TikZ code, starting with " "\\begin{tikzpicture} and ending with \\end{tikzpicture}. No prose, no markdown fences." ) scene = ("There is a circle centered at the origin with radius 3. Point A lies on the " "circle at 40 degrees. Point B lies on the circle at 200 degrees. Point M is the " "midpoint of segment AB.") msgs = [{"role": "system", "content": SYSTEM}, {"role": "user", "content": f"Scene:\n{scene}\n\nReturn the TikZ figure."}] prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True, enable_thinking=False) out = model.generate(**tok(prompt, return_tensors="pt").to(model.device), max_new_tokens=512, do_sample=False) print(tok.decode(out[0][tok(prompt, return_tensors="pt")["input_ids"].shape[1]:], skip_special_tokens=True))
cannot import name 'EncoderDecoderCache' from 'transformers'
http://www.cnnetsun.cn/news/4028516.html

相关文章:

  • 国家工程技术研究中心申报条件有哪些
  • Python Django电商比价系统:从爬虫到智能Agent的全栈实践
  • 智能代码搜索:从向量化到混合检索,揭秘“离谱快”背后的技术架构
  • RTX Spark:在个人PC上搭建GPU加速的Spark大数据与AI开发环境
  • 三步装好Android Studio中文语言包,开发界面5分钟变中文
  • SH9持续同调拓扑正则性与无导数奇点检测:拓扑表示对应等价条件与Navier-Stokes奇异性的拓扑刻画
  • 终极指南:如何使用Holehe进行邮箱账号安全检测
  • Jinq 社区精选:用户最常问的 20 个问题与解答
  • klogg日志分析终极指南:如何快速检索10GB级日志文件(安装、搜索与实时监控全攻略)
  • ElasticSearch Paramedic源码解析:Ember.js前端架构与ElasticSearch API交互原理
  • 微信聊天记录导出其实很简单:换手机前,我把三年对话永久存进了本地
  • 新手必看:R3PLAYX界面导航与基础操作完全指南
  • Minum框架扩展指南:从零开发自定义数据库引擎的完整教程
  • 高阶C++-SFINAE
  • 开源共享记忆服务Lindy:突破AI上下文限制,构建可记忆的智能应用
  • mcrcon 跨平台编译实战:看懂一条裸命令,三端构建零报错
  • Java校园智能车辆管理系统设计与实现
  • 材料告急时,FGO玩家需要的不是一个攻略站
  • 一张内部图来解读UMI AIGC SAAS,优秘智能到底想做什么?
  • 10个Shapiq入门示例:从表格数据到图像识别的可解释性分析
  • HTTPS协议原理、优化与安全实践指南
  • 探索Kaizoku核心功能:为什么它是自托管漫画爱好者的必备工具
  • ROM修改进阶教程------如何打开系统的一些常用开关等指令 备份收藏 【一】
  • Buzz音频转录终极指南:从零开始实现免费离线语音转文字
  • Git多人协作开发模式对比与实战优化
  • 汽车功能安全与网络安全融合:从ISO 26262到纵深防御的“双零愿景”实践
  • Python游戏开发入门:Pygame框架详解与实践
  • AI网络优化:RoCEv2与QoS调度实战指南
  • 3步搞定Gentoo安装:gentoo-install图形化安装工具完整指南
  • 如何在消费级硬件上部署LLM?LLM Interview Questions and Answers Hub中的实用技巧