Spaces:
Sleeping
Sleeping
zhanganduo
commited on
Commit
·
5beeda0
1
Parent(s):
30a1fc7
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
def extract_excel_content(file, rows, cols):
|
| 5 |
+
try:
|
| 6 |
+
# 读取上传的Excel文件
|
| 7 |
+
df = pd.read_excel(file, engine='openpyxl')
|
| 8 |
+
|
| 9 |
+
# 获取特定行数和列数的数据
|
| 10 |
+
extracted_data = df.iloc[:rows, :cols]
|
| 11 |
+
return extracted_data.to_string()
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return f"Error: {str(e)}"
|
| 14 |
+
|
| 15 |
+
# 创建Gradio界面
|
| 16 |
+
with gr.Blocks() as demo:
|
| 17 |
+
gr.Markdown("# Excel内容提取工具")
|
| 18 |
+
gr.Markdown("上传您的Excel文件并指定需要提取的行数和列数")
|
| 19 |
+
|
| 20 |
+
file_input = gr.File(label="上传Excel文件", type="file")
|
| 21 |
+
row_input = gr.Number(label="行数 (例如 5)", value=5, precision=0)
|
| 22 |
+
col_input = gr.Number(label="列数 (例如 3)", value=3, precision=0)
|
| 23 |
+
output_text = gr.Textbox(label="提取内容")
|
| 24 |
+
|
| 25 |
+
extract_button = gr.Button("提取内容")
|
| 26 |
+
|
| 27 |
+
extract_button.click(fn=extract_excel_content, inputs=[file_input, row_input, col_input], outputs=output_text)
|
| 28 |
+
|
| 29 |
+
# 运行Gradio应用
|
| 30 |
+
demo.launch()
|