Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
def plot_graph(file): | |
df = pd.read_csv(file.name) | |
# Assuming 'Date' is formatted as 'YYYY-MM-DD' in the CSV. | |
df['Date'] = pd.to_datetime(df['Date']) | |
# Set figure and axes | |
plt.figure(figsize=(10, 6)) | |
# Plot each species as a separate line | |
for species in df['Species'].unique(): | |
species_data = df[df['Species'] == species] | |
plt.plot(species_data['Date'], species_data['Count'], label=species, marker='o') | |
# Setting labels and title | |
plt.xlabel('Date') | |
plt.ylabel('Count') | |
plt.title('Observations of Species Over Time') | |
plt.legend(title='Species') | |
plt.grid(True) | |
plt.xticks(rotation=45) | |
# Save the plot | |
plot_filename = 'plot.png' | |
plt.savefig(plot_filename) | |
plt.close() | |
return plot_filename | |
examples = [ | |
["example1.csv"], | |
] | |
interface = gr.Interface( | |
fn=plot_graph, | |
inputs=gr.File(label="Upload CSV File"), | |
outputs=gr.Image(type="filepath", label="Generated Graph"), | |
title="Species Observation Plotter", | |
examples=examples | |
) | |
interface.launch() | |