arif670 commited on
Commit
722b3d3
·
verified ·
1 Parent(s): 9a5fcdc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -39
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
- def generate_output(topic):
6
- """
7
- This function simulates generating a graphical output based on the input topic.
8
- In a real-world scenario, this function would use more sophisticated logic
9
- to generate relevant data and create visualizations.
10
-
11
- Args:
12
- topic: The input topic entered by the user.
13
-
14
- Returns:
15
- A matplotlib figure object.
16
- """
17
-
18
- # Example: Generate random data for a simple bar chart
19
- data = np.random.rand(5)
20
- labels = ['A', 'B', 'C', 'D', 'E']
21
-
22
- # Create a bar chart
23
- fig, ax = plt.subplots()
24
- ax.bar(labels, data)
25
- ax.set_title(f"Example Chart for: {topic}")
26
- ax.set_xlabel("Categories")
27
- ax.set_ylabel("Values")
28
-
29
- return fig
30
-
31
- # Create the Gradio interface
32
- iface = gr.Interface(
33
- fn=generate_output,
34
- inputs="text",
35
- outputs="matplotlib",
36
- title="Children's Project Visualizer",
37
- description="Enter a topic and see a relevant visualization!",
38
  )
39
 
40
- # Launch the app (comment out for deployment on Hugging Face Spaces)
41
- # iface.launch() # Comment out for deployment
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)