Spaces:
Sleeping
Sleeping
harisali
commited on
Commit
·
f5dce09
1
Parent(s):
4a4d67b
ui update
Browse files
app.py
CHANGED
|
@@ -586,8 +586,12 @@ def get_evolution_stats_chart(pokemon_name: str) -> str:
|
|
| 586 |
}
|
| 587 |
}
|
| 588 |
}
|
| 589 |
-
return json.dumps(chart_config)
|
| 590 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
|
| 592 |
final_answer = FinalAnswerTool()
|
| 593 |
|
|
@@ -656,38 +660,74 @@ def pokemon_ui(pokemon_name):
|
|
| 656 |
return "Please enter a Pokémon name (e.g., pikachu).", "", ""
|
| 657 |
|
| 658 |
try:
|
| 659 |
-
#
|
| 660 |
evo_result = get_pokemon_evolution_visual(pokemon_name)
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
</div>
|
| 668 |
-
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
|
| 669 |
-
<script>
|
| 670 |
-
const ctx = document.getElementById('statsChart').getContext('2d');
|
| 671 |
-
new Chart(ctx, {chart_config});
|
| 672 |
-
</script>
|
| 673 |
-
"""
|
| 674 |
html_filename = f"{pokemon_name.lower()}_evolution.html"
|
| 675 |
evolution_html = ""
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
except Exception as e:
|
| 681 |
return f"Error processing {pokemon_name}: {str(e)}", "", ""
|
| 682 |
|
|
|
|
|
|
|
| 683 |
if __name__ == "__main__":
|
| 684 |
iface = gr.Interface(
|
| 685 |
fn=pokemon_ui,
|
| 686 |
-
inputs=gr.Textbox(label="Pokemon Name"),
|
| 687 |
outputs=[
|
| 688 |
-
gr.
|
| 689 |
-
gr.HTML(label="Evolution
|
| 690 |
-
gr.HTML(label="Evolution Stats Chart
|
| 691 |
],
|
|
|
|
|
|
|
| 692 |
)
|
| 693 |
-
iface.launch(share=True)
|
|
|
|
| 586 |
}
|
| 587 |
}
|
| 588 |
}
|
|
|
|
| 589 |
|
| 590 |
+
chart_filename = f"{pokemon_name.lower()}_evolution_stats.json"
|
| 591 |
+
with open(chart_filename, "w") as f:
|
| 592 |
+
json.dump(chart_config, f, indent=2)
|
| 593 |
+
|
| 594 |
+
return f"Radar chart for {pokemon_name.title()}'s evolution chain stats saved to '{chart_filename}'."
|
| 595 |
|
| 596 |
final_answer = FinalAnswerTool()
|
| 597 |
|
|
|
|
| 660 |
return "Please enter a Pokémon name (e.g., pikachu).", "", ""
|
| 661 |
|
| 662 |
try:
|
| 663 |
+
# Get evolution chain and stats
|
| 664 |
evo_result = get_pokemon_evolution_visual(pokemon_name)
|
| 665 |
+
chart_result = get_evolution_stats_chart(pokemon_name)
|
| 666 |
+
|
| 667 |
+
# Combine text results
|
| 668 |
+
text_output = f"Evolution Result:\n{evo_result}\n\nChart Result:\n{chart_result}"
|
| 669 |
+
|
| 670 |
+
# Read evolution HTML
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 671 |
html_filename = f"{pokemon_name.lower()}_evolution.html"
|
| 672 |
evolution_html = ""
|
| 673 |
+
try:
|
| 674 |
+
if os.path.exists(html_filename):
|
| 675 |
+
with open(html_filename, "r", encoding="utf-8") as f:
|
| 676 |
+
evolution_html = f.read()
|
| 677 |
+
else:
|
| 678 |
+
evolution_html = "<p>Evolution HTML file not found.</p>"
|
| 679 |
+
except Exception as e:
|
| 680 |
+
evolution_html = f"<p>Error reading evolution HTML: {str(e)}</p>"
|
| 681 |
+
|
| 682 |
+
# Read chart JSON and create chart HTML
|
| 683 |
+
chart_filename = f"{pokemon_name.lower()}_evolution_stats.json"
|
| 684 |
+
chart_html = ""
|
| 685 |
+
try:
|
| 686 |
+
if os.path.exists(chart_filename):
|
| 687 |
+
with open(chart_filename, "r") as f:
|
| 688 |
+
chart_config = json.load(f)
|
| 689 |
+
|
| 690 |
+
# Create proper chart HTML
|
| 691 |
+
chart_html = f"""
|
| 692 |
+
<!DOCTYPE html>
|
| 693 |
+
<html>
|
| 694 |
+
<head>
|
| 695 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
|
| 696 |
+
</head>
|
| 697 |
+
<body>
|
| 698 |
+
<div style="width: 600px; height: 400px; margin: auto;">
|
| 699 |
+
<canvas id="statsChart"></canvas>
|
| 700 |
+
</div>
|
| 701 |
+
<script>
|
| 702 |
+
const ctx = document.getElementById('statsChart').getContext('2d');
|
| 703 |
+
const chartConfig = {json.dumps(chart_config, indent=2)};
|
| 704 |
+
new Chart(ctx, chartConfig);
|
| 705 |
+
</script>
|
| 706 |
+
</body>
|
| 707 |
+
</html>
|
| 708 |
+
"""
|
| 709 |
+
else:
|
| 710 |
+
chart_html = "<p>Chart JSON file not found.</p>"
|
| 711 |
+
except Exception as e:
|
| 712 |
+
chart_html = f"<p>Error creating chart HTML: {str(e)}</p>"
|
| 713 |
+
|
| 714 |
+
return text_output, evolution_html, chart_html
|
| 715 |
+
|
| 716 |
except Exception as e:
|
| 717 |
return f"Error processing {pokemon_name}: {str(e)}", "", ""
|
| 718 |
|
| 719 |
+
|
| 720 |
+
# Also fix the Gradio interface
|
| 721 |
if __name__ == "__main__":
|
| 722 |
iface = gr.Interface(
|
| 723 |
fn=pokemon_ui,
|
| 724 |
+
inputs=gr.Textbox(label="Pokemon Name", placeholder="Enter Pokemon name (e.g., pikachu)"),
|
| 725 |
outputs=[
|
| 726 |
+
gr.Textbox(label="Results", lines=6), # Changed from HTML to Textbox for the text output
|
| 727 |
+
gr.HTML(label="Evolution Visualization"),
|
| 728 |
+
gr.HTML(label="Evolution Stats Chart"),
|
| 729 |
],
|
| 730 |
+
title="Pokemon Evolution Visualizer",
|
| 731 |
+
description="Enter a Pokemon name to see its evolution chain and stats comparison"
|
| 732 |
)
|
| 733 |
+
iface.launch(share=True)
|