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

2024-09-08 04:44

本文主要是介绍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

这篇关于240907-Gradio插入Mermaid流程图并自适应浏览器高度的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1147152

相关文章

如何关闭Mac的Safari通知? 3招教你关闭Safari浏览器网站通知的技巧

《如何关闭Mac的Safari通知?3招教你关闭Safari浏览器网站通知的技巧》当我们在使用Mac电脑专注做一件事情的时候,总是会被一些消息推送通知所打扰,这时候,我们就希望关闭这些烦人的Mac通... Safari 浏览器的「通知」功能本意是为了方便用户及时获取最新资讯,但很容易被一些网站滥用,导致我们

全解析CSS Grid 的 auto-fill 和 auto-fit 内容自适应

《全解析CSSGrid的auto-fill和auto-fit内容自适应》:本文主要介绍了全解析CSSGrid的auto-fill和auto-fit内容自适应的相关资料,详细内容请阅读本文,希望能对你有所帮助... css  Grid 的 auto-fill 和 auto-fit/* 父元素 */.gri

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)

《使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)》PPT是一种高效的信息展示工具,广泛应用于教育、商务和设计等多个领域,PPT文档中常常包含丰富的图片内容,这些图片不仅提升了... 目录一、引言二、环境与工具三、python 提取PPT背景图片3.1 提取幻灯片背景图片3.2 提取

MySQL INSERT语句实现当记录不存在时插入的几种方法

《MySQLINSERT语句实现当记录不存在时插入的几种方法》MySQL的INSERT语句是用于向数据库表中插入新记录的关键命令,下面:本文主要介绍MySQLINSERT语句实现当记录不存在时... 目录使用 INSERT IGNORE使用 ON DUPLICATE KEY UPDATE使用 REPLACE

使用DrissionPage控制360浏览器的完美解决方案

《使用DrissionPage控制360浏览器的完美解决方案》在网页自动化领域,经常遇到需要保持登录状态、保留Cookie等场景,今天要分享的方案可以完美解决这个问题:使用DrissionPage直接... 目录完整代码引言为什么要使用已有用户数据?核心代码实现1. 导入必要模块2. 关键配置(重点!)3.

Jmeter如何向数据库批量插入数据

《Jmeter如何向数据库批量插入数据》:本文主要介绍Jmeter如何向数据库批量插入数据方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Jmeter向数据库批量插入数据Jmeter向mysql数据库中插入数据的入门操作接下来做一下各个元件的配置总结Jmete

Python中__new__()方法适应及注意事项详解

《Python中__new__()方法适应及注意事项详解》:本文主要介绍Python中__new__()方法适应及注意事项的相关资料,new()方法是Python中的一个特殊构造方法,用于在创建对... 目录前言基本用法返回值单例模式自定义对象创建注意事项总结前言new() 方法在 python 中是一个

JavaWeb-WebSocket浏览器服务器双向通信方式

《JavaWeb-WebSocket浏览器服务器双向通信方式》文章介绍了WebSocket协议的工作原理和应用场景,包括与HTTP的对比,接着,详细介绍了如何在Java中使用WebSocket,包括配... 目录一、概述二、入门2.1 POM依赖2.2 编写配置类2.3 编写WebSocket服务2.4 浏