Spaces:
Sleeping
Sleeping
##### Import all the stuff | |
import gradio as gr | |
import plotly.graph_objects as go | |
import pandas as pd | |
import plotly.io as pio | |
import base64 | |
#### Get the files | |
TrimmedDataFrame = pd.read_csv('TrimmedDataFrame.csv') | |
#### Creating a method to compare 2 pals | |
def compare2pals(x, y): | |
x = TrimmedDataFrame[TrimmedDataFrame["name"] == x] | |
y = TrimmedDataFrame[TrimmedDataFrame["name"] == y] | |
trace0 = go.Scatterpolar( | |
r = [x['hp'].values[0], x['melee attack'].values[0], x['remote attack'].values[0], x['defense'].values[0]], | |
theta = ['hp','melee attack','remote attack','defense'], | |
fill = 'toself', | |
name = x.name.values[0] | |
) | |
trace1 = go.Scatterpolar( | |
r = [y['hp'].values[0], y['melee attack'].values[0], y['remote attack'].values[0], y['defense'].values[0]], | |
theta = ['hp','melee attack','remote attack','defense'], | |
fill = 'toself', | |
name = y.name.values[0] | |
) | |
trace2 = go.Scatterpolar( | |
r=[x['kindling'].values[0], x['watering'].values[0], x['planting'].values[0], x['generate electricity'].values[0], | |
x['handiwork'].values[0], x['gathering'].values[0], x['logging'].values[0], x['mining'].values[0], x['medicine'].values[0], | |
x['cooling'].values[0], x['ranching'].values[0], x['transporting'].values[0]], | |
theta=['kindling', 'watering', 'planting', 'generate electricity', 'handiwork', 'gathering', 'logging', 'mining', 'medicine', 'cooling', | |
'ranching', 'transporting'], | |
fill='toself', | |
name = x.name.values[0] | |
) | |
trace3 = go.Scatterpolar( | |
r=[y['kindling'].values[0], y['watering'].values[0], y['planting'].values[0], y['generate electricity'].values[0], | |
y['handiwork'].values[0], y['gathering'].values[0], y['logging'].values[0], y['mining'].values[0], y['medicine'].values[0], | |
y['cooling'].values[0], y['ranching'].values[0], y['transporting'].values[0]], | |
theta=['kindling', 'watering', 'planting', 'generate electricity', 'handiwork', 'gathering', 'logging', 'mining', 'medicine', 'cooling', | |
'ranching', 'transporting'], | |
fill='toself', | |
name = y.name.values[0] | |
) | |
combatdata = [trace0, trace1] | |
basedata = [trace2, trace3] | |
# Your combatlayout and baselayout definitions remain unchanged... | |
combatlayout = go.Layout( | |
polar = dict( | |
radialaxis = dict( | |
visible = True, | |
range = [0, 160] | |
) | |
), | |
showlegend = True, | |
title = "{} vs {}".format(x.name.values[0],y.name.values[0]) | |
) | |
baselayout = go.Layout( | |
polar = dict( | |
radialaxis = dict( | |
visible = True, | |
range = [0, 5] | |
) | |
), | |
showlegend = True, | |
title = "{} vs {}".format(x.name.values[0],y.name.values[0]) | |
) | |
combatfig = go.Figure(data=[trace0, trace1], layout=combatlayout) | |
basefig = go.Figure(data=[trace2, trace3], layout=baselayout) | |
# Define file paths for the images | |
combat_image_path = "combat_image.png" | |
base_image_path = "base_image.png" | |
# Save Plotly figures as images | |
pio.write_image(combatfig, combat_image_path) | |
pio.write_image(basefig, base_image_path) | |
# Return the file paths | |
return combat_image_path, base_image_path | |
#### Make a gradio interface prompt | |
# Gradio interface function that calls compare2pals and returns the image paths | |
def gradio_compare2pals_interface(pal1, pal2): | |
combat_image_path, base_image_path = compare2pals(pal1, pal2) | |
return combat_image_path, base_image_path | |
# Set up Gradio interface | |
iface = gr.Interface( | |
fn=gradio_compare2pals_interface, | |
inputs=[gr.Textbox(label="First Pal Name"), gr.Textbox(label="Second Pal Name")], | |
outputs=[gr.Image(label="Combat Stats"), gr.Image(label="Base Stats")], | |
examples=[["Lamball", "Pyrin"]] # Make sure these are valid names in your DataFrame | |
) | |
iface.launch() |