Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import matplotlib.pyplot as plt
|
|
|
|
| 3 |
import numpy as np
|
| 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 |
-
description="Enter a topic and see a relevant visualization!",
|
| 38 |
)
|
| 39 |
|
| 40 |
-
# Launch the app
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# For deployment on Hugging Face Spaces, use the following line instead:
|
| 44 |
-
gr.Interface.launch(show=False) # Replace with your deployment command (see below)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
+
import seaborn as sns
|
| 4 |
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import plotly.express as px
|
| 7 |
+
|
| 8 |
+
# Function to generate graphical output based on topic
|
| 9 |
+
def generate_graph(topic):
|
| 10 |
+
# Example function that generates a bar chart for demonstration
|
| 11 |
+
if topic.lower() == 'animals':
|
| 12 |
+
data = {'Animals': ['Lion', 'Tiger', 'Bear', 'Elephant'],
|
| 13 |
+
'Count': [10, 12, 5, 8]}
|
| 14 |
+
df = pd.DataFrame(data)
|
| 15 |
+
fig = px.bar(df, x='Animals', y='Count', title='Animal Count')
|
| 16 |
+
elif topic.lower() == 'fruits':
|
| 17 |
+
data = {'Fruit': ['Apple', 'Banana', 'Cherry', 'Date'],
|
| 18 |
+
'Count': [20, 15, 30, 10]}
|
| 19 |
+
df = pd.DataFrame(data)
|
| 20 |
+
fig = px.pie(df, names='Fruit', values='Count', title='Fruit Distribution')
|
| 21 |
+
else:
|
| 22 |
+
# Default graph if no matching topic
|
| 23 |
+
data = {'Topic': ['A', 'B', 'C', 'D'],
|
| 24 |
+
'Value': [25, 40, 15, 20]}
|
| 25 |
+
df = pd.DataFrame(data)
|
| 26 |
+
fig = px.line(df, x='Topic', y='Value', title='Example Line Graph')
|
| 27 |
+
|
| 28 |
+
return fig
|
| 29 |
+
|
| 30 |
+
# Build the Gradio interface
|
| 31 |
+
interface = gr.Interface(
|
| 32 |
+
fn=generate_graph,
|
| 33 |
+
inputs=gr.Textbox(label="Enter Topic (e.g., Animals, Fruits)"),
|
| 34 |
+
outputs=gr.Plot(),
|
| 35 |
+
live=True,
|
| 36 |
+
title="Children's School Project Graph Generator",
|
| 37 |
+
description="Enter a topic and see a graphical representation of related data."
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
+
# Launch the app
|
| 41 |
+
interface.launch(share=True)
|
|
|
|
|
|
|
|
|