首页 > 其他分享 >240907-Gradio插入Mermaid流程图并自适应浏览器高度

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

时间:2024-09-18 11:23:05浏览次数:3  
标签:gr -- Gradio height 240907 Mermaid John Teacher mermaid


A. 最终效果

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

B. 示例代码

import gradio as gr

mermaid_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">
journey
    title Create AI
    section Training
      Format DataSet Inputs Files, Data Splits: 5: Teacher
      Model Build w/ SKLearn, TF, Pytorch: 3: Student
      Determine Model Performance: 1: Teacher, Student
    section Deploy
      Web Deploy Local and Cloud: 5: Teacher
      Architecture Spaces Gradio Streamlit Heroku AWS Azure and GCCP: 5: Teacher
    section Testing
      Test Model with Input Datasets: 5: Teacher
      Examples. Inputs that Work, Inputs That Break Model: 5: Teacher
      Governance - Analyze, Publish Fairness, Equity, Bias for Datasets and Outputs: 5: Teacher
</div>

<div class="mermaid">
sequenceDiagram
    participant Alice
    participant Bob
    Alice->>John: Hello John, how are you?
    loop Healthcheck
        John->>John: Fight against hypochondria
    end
    Note 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_code


with 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. 参考文献


标签:gr,--,Gradio,height,240907,Mermaid,John,Teacher,mermaid
From: https://blog.51cto.com/guokliu/12044617

相关文章

  • 20240907_221939 公共基础 列表
    20240826_222457公共基础算法的概念_13127233的技术博客_51CTO博客https://blog.51cto.com/u_13137233/1184633920240826_222637公共基础算法的特征_13127233的技术博客_51CTO博客https://blog.51cto.com/u_13137233/1184637520240826_222817公共基础算法设计基本方法_13......
  • 20240907 模拟赛总结
    期望得分:100+80+70+0=250实际得分:90+20+100+0=210今天挂分挂惨了!!!T1模拟即可,几分钟就写完了,但是有一些cornercase非常麻烦,吃饭的时候意识到没特判,最后几分钟马上跑上来改,想不到改错了?。。T2感觉是那种很技巧性的数学题,考场上只写了80分暴力,但是,但是,线性筛的最后一个版本......
  • 202409071506,开始写代码,从0开始 验证基本架子
    由于视频教程里面用的VS2105所以照抄。 开发环境是VS2015,WIN10.  VS2015在今天看来是一个很古老的开发环境了,估计都很难找到安装包。(各种安装包:https://www.cnblogs.com/zjoch/p/5694013.html)用:vs2015.ent_chs.iso(3.88GB(4,172,560,384字节))这个安装包,安装过程出......
  • 基于Video-Retalking-Gradio的AI数字人
    随着数字内容的普及,如何在视频中实现高精度的音频与唇形同步成为一个重要课题。传统方法通常需要大量的人工干预和调整,效果也往往不尽如人意。为了应对这一挑战,VideoReTalking系统应运而生。由西安电子科技大学和腾讯AI实验室的研究人员联合开发,VideoReTalking是一个创新......
  • 基于Easy-Wav2lip-Gradio的AI数字人
    数字人技术近年来在多个领域得到广泛应用,从虚拟主播到电影特效,都需要精确的音视频同步技术来实现逼真的效果。传统的嘴型同步技术往往面临着准确性不高、处理速度慢等问题。为了解决这些问题,原有的Wav2Lip项目应运而生。Wav2Lip通过人工智能技术,实现了音频和视频的高精度同......
  • 20240907_004551 mysql 视图 创建视图
    很幸苦的获取数据SELECTstudent.id,student.nameASsname,class.nameAScname,class.detailFROMstudentINNERJOINclassONstudent.cid=class.id存在的问题下次要再拿这样的数据重写语句很麻烦希望上面的查询结果直接就作为虚拟表的本体创建视图语法createvi......
  • 视频处理基础之gradio框架实现
    这些函数是用于处理视频文件的Python代码片段,它们依赖于`ffmpeg`和`ffprobe`工具,这些工具是`FFmpeg`项目的一部分,用于处理视频和音频数据。下面是每个函数的用途和用法的总结:1.`ffmpeg_installed()`函数:  -用途:检查系统是否安装了`ffmpeg`工具。  -用法:调用此函数......
  • 20240907_051745 python 正则表达式 常见元字符
    •.:匹配任意单个字符•\d:匹配数字(等价于[0-9])•\w:匹配字母、数字、下划线(等价于[a-zA-Z0-9_])•\s:匹配空格、制表符、换行符等空白字符•^:匹配开头•$:匹配结尾•*:匹配前面的字符零次或多次•+:匹配前面的字符一次或多次•?:匹配前面的字符零次或一次•[]:匹配方括......
  • 20240907_061745 python 正则表达式 re.match方法
    情况一从头匹配匹配成功的数据可以通过匹配的对象的group()方法获取关注一下匹配不成功的情况情况二从中间匹配......
  • Typora 适配高版本 Mermaid
    Typora适配高版本Mermaid查看Mermaid版本info下载最新的mermaid.min.js文件在搜索框输入CDNhttps://cdn.jsdelivr.net/npm/mermaid@11/替换Typora的window.html文件<script> constinterval=setInterval(()=>{ console.log('checkmermaid...'); if......