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

240907-Gradio插入Mermaid流程图并自适应浏览器高度

A. 最终效果

在这里插入图片描述

B. 示例代码

import gradio as grmermaid_code = """
<iframe srcdoc='
<!DOCTYPE html>
<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width" /><title>My static Space</title><link rel="stylesheet" href="style.css" /><script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script><script>mermaid.initialize({startOnLoad:true});</script><script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script>// 当文档内容加载完成时,初始化并渲染 Mermaid 图表document.addEventListener("DOMContentLoaded", function() {mermaid.initialize({ startOnLoad: true });});
</script> </head><body><div class="mermaid">
journeytitle Create AIsection TrainingFormat DataSet Inputs Files, Data Splits: 5: TeacherModel Build w/ SKLearn, TF, Pytorch: 3: StudentDetermine Model Performance: 1: Teacher, Studentsection DeployWeb Deploy Local and Cloud: 5: TeacherArchitecture Spaces Gradio Streamlit Heroku AWS Azure and GCCP: 5: Teachersection TestingTest Model with Input Datasets: 5: TeacherExamples. Inputs that Work, Inputs That Break Model: 5: TeacherGovernance - Analyze, Publish Fairness, Equity, Bias for Datasets and Outputs: 5: Teacher
</div><div class="mermaid">
sequenceDiagramparticipant Aliceparticipant BobAlice->>John: Hello John, how are you?loop HealthcheckJohn->>John: Fight against hypochondriaendNote right of John: Rational thoughts<br/>prevail...John-->>Alice: Great!John->>Bob: How about you?Bob-->>John: Jolly good!
</div><div class="card">
<h1>Welcome to the Mermaid Modeler Tip Sheet</h1><p>You can use Mermaid inside HTML5 by including the script and a div with the class or mermaid.</p><p>Documentation is located here: <a href="https://mermaid.js.org/syntax/flowchart.html" target="_blank">Mermaid documentation</a>.</p>
</div><div class="mermaid">graph TD;A[开始] --> B{是否正常运行?};B -->|是| C[很好];B -->|否| D[进行修复];D --> A;
</div></body>
</html> ' width="100%" height="800px" style="border:none;">
</iframe>
"""css = """
/* ⭐️ 流程图的css*/
body {padding: 2rem;font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
}h1 {font-size: 16px;margin-top: 0;
}p {color: rgb(107, 114, 128);font-size: 15px;margin-bottom: 10px;margin-top: 5px;
}.card {max-width: 620px;margin: 0 auto;padding: 16px;border: 1px solid lightgray;border-radius: 16px;
}.card p:last-child {margin-bottom: 0;
}/* ⭐️ 自适应浏览器高度的css*/
.contain { display: flex; flex-direction: column; height: 95vh; padding: 10px; /* Optional: adjust padding around the container */gap: 8px; /* Reduce the gap between components */
}
.gradio-container { height: 100vh !important; 
}
#html-component { flex-grow: 1; overflow: auto; 
}
.fixed-textbox { height: 40px; /* Set a fixed height for the textbox */flex-shrink: 0; /* Prevent shrinking */
}
.fixed-button { height: 40px; /* Set a fixed height for the button */flex-shrink: 0; /* Prevent shrinking */
}
* {border: 1px solid black; /* 设置所有元素的边框宽度为1px,样式为实线,颜色为黑色 */
}
"""def display_diagram():return mermaid_codewith gr.Blocks(css=css) as demo:with gr.Row():with gr.Column(elem_classes="contain"):gr.HTML(mermaid_code, elem_id='html-container')with gr.Column(elem_classes="contain"):html = gr.HTML(mermaid_code, elem_id="html-component")msg = gr.Textbox()clear = gr.Button("Clear",  elem_classes="fixed-button")demo.launch()

C. 参考文献

  • Allow gr.Chatbot to fill all height of rest of space · Issue #4001 · gradio-app/gradio
  • mariashay/DataViz-Mermaid at main
http://www.lryc.cn/news/432380.html

相关文章:

  • ubuntu 安装python3 教程
  • NOR Flash、NAND Flash……
  • 【高性能代码】提高代码的性能有哪些方式,如何写出高性能代码,一段代码如何提高这段代码的执行性能,高性能代码开发
  • 2024整理 iptables防火墙学习笔记大全_modepro iptables
  • 实验记录 | 点云处理 | K-NN算法3种实现的性能比较
  • 【OJ】常用技巧
  • Redis:Redis性能变慢的原因
  • Linux多线程——利用C++模板对pthread线程库封装
  • SpringBoot教程(十五) | SpringBoot集成RabbitMq(消息丢失、消息重复、消息顺序、消息顺序)
  • TensorRT-LLM高级用法
  • 文心一言功能新升级:读文档、懂翻译、能识图
  • C++机试——走方格的方案
  • Bootstrap 字体图标无法显示问题,<i>标签字体图标无法显示问题
  • docker registry 仓库加密
  • 利用高德+ArcGIS优雅获取任何感兴趣的矢量边界
  • 炮弹【USACO】
  • python如何读取excel文件内的数据
  • Java项目: 基于SpringBoot+mybatis+maven+mysql教师工作量管理系统(含源码+数据库+毕业论文)
  • 项目开发--数据库--postgresql数据库操作
  • c语言——用一维数组输出杨辉三角形
  • Codeforces Round 971 (Div. 4) (A~G1)
  • 为什么构造函数不能为虚函数?为什么析构函数可以为虚函数,如果不设为虚函数可能会存在什么问题?
  • 【数据结构】单链表功能的实现
  • 最新车型库大全|阿里云实现调用API接口
  • 70. 爬楼梯
  • pytorch正向传播没问题,loss.backward()使定义的神经网络中权重参数变为nan
  • ❤《实战纪录片 1 》原生开发小程序中遇到的问题和解决方案
  • 2024.9.6 作业
  • 2024年架构设计师论文-“模型驱动架构设计方法及其应用”
  • Tapd敏捷开发平台的使用心得