hmb HF staff commited on
Commit
8f8897d
·
verified ·
1 Parent(s): 6b066d4

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. __pycache__/run.cpython-311.pyc +0 -0
  2. run.ipynb +1 -0
  3. run.py +62 -0
  4. screenshot.png +0 -0
__pycache__/run.cpython-311.pyc ADDED
Binary file (1.43 kB). View file
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: matrix_transpose"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import numpy as np\n", "\n", "import gradio as gr\n", "\n", "def transpose(matrix):\n", " return matrix.T\n", "\n", "demo = gr.Interface(\n", " transpose,\n", " gr.Dataframe(type=\"numpy\", datatype=\"number\", row_count=5, col_count=3, show_fullscreen_button=True),\n", " \"numpy\",\n", " examples=[\n", " [np.zeros((3, 3)).tolist()],\n", " [np.ones((2, 2)).tolist()],\n", " [np.random.randint(0, 10, (3, 10)).tolist()],\n", " [np.random.randint(0, 10, (10, 3)).tolist()],\n", " [np.random.randint(0, 10, (10, 10)).tolist()],\n", " ],\n", " cache_examples=False\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import pandas as pd
3
+ import gradio as gr
4
+
5
+ # Load the Pokémon Cards dataset from Hugging Face
6
+ dataset = load_dataset("TheFusion21/PokemonCards")
7
+ df = pd.DataFrame(dataset["train"])
8
+
9
+ display_columns = ["name", "hp"] + [col for col in df.columns if col not in ["image_url", "name", "hp"]]
10
+ display_df = df[display_columns]
11
+
12
+ def style_df(df):
13
+ hp_min = df['hp'].min()
14
+ hp_max = df['hp'].max()
15
+
16
+ def color_hp(val):
17
+ norm_val = (val - hp_min) / (hp_max - hp_min)
18
+ r = int(255 * (1 - norm_val))
19
+ g = int(255 * norm_val)
20
+ return f'background-color: rgba({r}, {g}, 0, 0.2)'
21
+
22
+ styled = df.style.applymap(color_hp, subset=['hp'])
23
+ return styled
24
+
25
+ # Function to filter data based on user input
26
+ def filter_cards(set_name=None):
27
+ filtered_df = df.copy()
28
+ if set_name and set_name != "All":
29
+ filtered_df = filtered_df[filtered_df["set_name"] == set_name]
30
+ return style_df(filtered_df[display_columns])
31
+
32
+ def update_display(evt: gr.SelectData):
33
+ selected_data = df.iloc[evt.index[0]]
34
+ return selected_data["image_url"]
35
+
36
+ # Gradio interface
37
+ with gr.Blocks() as demo:
38
+ gr.Markdown("## Pokémon Cards Explorer")
39
+
40
+ with gr.Row():
41
+ set_filter = gr.Dropdown(
42
+ choices=["All"] + df["set_name"].unique().tolist(),
43
+ label="Filter by Set Name"
44
+ )
45
+
46
+ filtered_table = gr.DataFrame(style_df(display_df), show_fullscreen_button=True, show_search="search", max_chars=20, pinned_columns=1)
47
+ card_image = gr.Image(label="Card Image", height=200)
48
+
49
+ filter_button = gr.Button("Apply Filters")
50
+ filter_button.click(
51
+ filter_cards,
52
+ inputs=[set_filter],
53
+ outputs=filtered_table
54
+ )
55
+
56
+ filtered_table.select(
57
+ update_display,
58
+ None,
59
+ card_image
60
+ )
61
+
62
+ demo.launch()
screenshot.png ADDED