File size: 1,195 Bytes
8152368
 
 
 
1af183a
 
 
8152368
 
1af183a
 
 
f5d1103
1af183a
 
f5d1103
1af183a
 
 
 
 
 
 
 
 
 
8152368
f5d1103
 
1af183a
a30008c
 
 
 
8152368
1af183a
f2340ef
 
 
 
bc683d5
 
 
a30008c
f2340ef
 
bc683d5
8152368
bc683d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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()