Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,27 @@
|
|
| 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 |
-
if st.button("Plot Custom Chart"):
|
| 27 |
-
plot_custom_chart(x_values, y_values)
|
| 28 |
-
|
| 29 |
-
# Correlation Heatmap using Seaborn
|
| 30 |
-
st.subheader("Correlation Heatmap")
|
| 31 |
-
plot_correlation_heatmap(df)
|
| 32 |
-
|
| 33 |
-
# Function to plot custom chart
|
| 34 |
-
def plot_custom_chart(x_values, y_values):
|
| 35 |
-
try:
|
| 36 |
-
# Convert the X and Y values from string input to lists of integers
|
| 37 |
-
x_vals = list(map(int, x_values.split(',')))
|
| 38 |
-
y_vals = list(map(int, y_values.split(',')))
|
| 39 |
-
|
| 40 |
-
# Ensure both X and Y values have the same length
|
| 41 |
-
if len(x_vals) != len(y_vals):
|
| 42 |
-
st.error("Error: X and Y values must have the same number of elements.")
|
| 43 |
-
return
|
| 44 |
-
|
| 45 |
-
# Plot using Matplotlib
|
| 46 |
-
plt.figure(figsize=(8, 5))
|
| 47 |
-
plt.plot(x_vals, y_vals, marker='o', color='b', label="Data Points")
|
| 48 |
-
plt.title("Custom Data Visualization")
|
| 49 |
-
plt.xlabel("X Values")
|
| 50 |
-
plt.ylabel("Y Values")
|
| 51 |
-
plt.grid(True)
|
| 52 |
-
plt.legend()
|
| 53 |
-
|
| 54 |
-
# Display the plot
|
| 55 |
-
st.pyplot(plt)
|
| 56 |
-
|
| 57 |
-
except ValueError:
|
| 58 |
-
st.error("Error: Please make sure the values are valid integers.")
|
| 59 |
-
|
| 60 |
-
# Function to plot correlation heatmap
|
| 61 |
-
def plot_correlation_heatmap(df):
|
| 62 |
-
corr = df.corr() # Calculate correlation matrix
|
| 63 |
-
plt.figure(figsize=(10, 8))
|
| 64 |
-
sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f')
|
| 65 |
-
plt.title('Correlation Heatmap')
|
| 66 |
-
st.pyplot(plt) # Display in Streamlit
|
| 67 |
-
|
| 68 |
-
# Run the Streamlit interface
|
| 69 |
-
if __name__ == "__main__":
|
| 70 |
-
streamlit_interface()
|
| 71 |
|
| 72 |
|
|
|
|
| 1 |
+
def advanced_plot(df, chart_type):
|
| 2 |
+
plt.figure(figsize=(8, 6))
|
| 3 |
+
|
| 4 |
+
if chart_type == "Bar":
|
| 5 |
+
sns.barplot(x='Category', y='Value', data=df)
|
| 6 |
+
elif chart_type == "Line":
|
| 7 |
+
sns.lineplot(x='Category', y='Value', data=df)
|
| 8 |
+
elif chart_type == "Pie":
|
| 9 |
+
df.set_index('Category')['Value'].plot.pie(autopct='%1.1f%%', figsize=(8, 6))
|
| 10 |
+
|
| 11 |
+
plt.title(f'{chart_type} Chart')
|
| 12 |
+
plt.xlabel('Category')
|
| 13 |
+
plt.ylabel('Value')
|
| 14 |
+
return plt
|
| 15 |
+
|
| 16 |
+
def gradio_interface_advanced(file, chart_type):
|
| 17 |
+
df = pd.read_csv(file.name)
|
| 18 |
+
return advanced_plot(df, chart_type)
|
| 19 |
+
|
| 20 |
+
interface = gr.Interface(fn=gradio_interface_advanced,
|
| 21 |
+
inputs=[gr.File(label="Upload CSV"),
|
| 22 |
+
gr.Dropdown(["Bar", "Line", "Pie"], label="Select Chart Type")],
|
| 23 |
+
outputs=gr.Plot())
|
| 24 |
+
|
| 25 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|