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

python gradio 的输出展示组件

  1. HTML:展示HTML内容,适用于富文本或网页布局。
  2. JSON:以JSON格式展示数据,便于查看结构化数据。
  3. KeyValues:以键值对形式展示数据。
  4. Label:展示文本标签,适用于简单的文本输出。
  5. Markdown:支持Markdown格式的文本展示。
  6. Plot:展示图表,如matplotlib生成的图表。
  7. Text:用于显示文本,适合较长的输出。

1、json列子

import gradio as gr
import json# 示例 JSON 数据
json_data = {"name": "Gradio","type": "Library","languages": ["Python", "JavaScript"],"description": "Gradio is an open-source library that allows developers to build interactive applications with machine learning and data science projects."
}# 将 JSON 数据转换为字符串格式
json_str = json.dumps(json_data, indent=4)# 定义一个函数,它接受没有输入,并返回 JSON 字符串
def show_json():return json_str# 使用 Gradio 创建界面,JSON 组件展示数据
gr.Interface(fn=show_json,inputs=None, outputs='json').launch()

没有输入,点击generate显示了json数据 

2、html

import gradio as grdef show_html():return "<h1>Hello, Gradio!</h1><p>This is an HTML output.</p>"gr.Interface(fn=show_html,inputs=None,outputs="html"
).launch()

 

3、plot

import gradio as grdef process_list(my_list):# 对列表进行处理的示例函数return f"接收到列表,长度为: {my_list}"# 创建一个包含列表输入的界面
gr.Interface(process_list,gr.List(label="输入列表"),  # 定义输入为列表"text",title="列表输入示例"
).launch()

import gradio as gr
import plotly.graph_objects as go# 创建一个简单的Plotly图表
def create_plot(x_data, y_data):fig = go.Figure(data=go.Bar(x=x_data[0], y=y_data[0]))return fig# 创建Gradio界面
interface = gr.Interface(fn=create_plot,inputs=[gr.List(label="X Axis Data"),gr.List(label="Y Axis Data"),],outputs='plot',
)# 运行Gradio界面
interface.launch()

4、markdown

import gradio as gr# with open("example.md", "r") as f:
#     md_content = f.read()def show_markdown(markdown_text):return markdown_textinterface = gr.Interface(fn=show_markdown,inputs=gr.Textbox(lines=10), # value = md_contentoutputs=gr.Markdown()
)interface.launch()

http://www.lryc.cn/news/404569.html

相关文章:

  • SwiftUI 6.0(Xcode 16)新 PreviewModifier 协议让预览调试如虎添翼
  • STM32被拔网线 LWIP的TCP无法重连解决方案
  • Linux下开放指定端口
  • 亚马逊测评行为的识别与防范:教你如何搭建安全的测评环境
  • 如何通过成熟的外发平台,实现文档安全外发管理?
  • SCI一区级 | Matlab实现SSA-CNN-GRU-Multihead-Attention多变量时间序列预测
  • Mysql中的几种常见日志
  • 2024年7月22日(nfs samba)
  • 黑龙江网络安全等级保护测评策略概述
  • 笔记 7 :linux 011 注释,函 bread () , get_hash_table () , find_buffer ()
  • vscode配置latex环境制作【文档、简历、resume】
  • 如何学习Spark:糙快猛的大数据之旅
  • 交换机(Switches)和桥(Bridges)的区别
  • 基于springboot+vue的汽车租赁管理系统
  • 《0基础》学习Python——第二十二讲__网络爬虫/<5>爬取豆瓣电影封面图
  • 全新UI自助图文打印系统小程序源码/自助云打印机前后端源码
  • yolo5图片视频、摄像头推理demo
  • Scala学习笔记19: 隐式转换和隐式参数
  • 用户登录安全是如何保证的?如何保证用户账号、密码安全?
  • Java 写一个可以持续发送消息的socket服务端
  • Ubuntu2204搭建ceph17
  • Druid 面试题及答案整理,最新面试题
  • 数据库基础与安装MYSQL数据库
  • 昇思25天学习打卡营第18天| DCGAN生成漫画头像
  • 【面试八股文】计算机操作系统
  • 宝塔Wordpress 插件 Redis object cache 导致内存很高 80%以上的原因和解决
  • node解析Excel中的考试题并实现在线做题功能
  • 怎么降低美国服务器硬盘故障率?
  • Java---后端事务管理
  • Leetcode 3223. Minimum Length of String After Operations