Sanjayraju30 commited on
Commit
1f3a826
·
verified ·
1 Parent(s): 0e66a48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -18
app.py CHANGED
@@ -1,19 +1,39 @@
1
- import torch
2
  import gradio as gr
3
- from diffusers import StableDiffusionPipeline
4
-
5
- model_id = "runwayml/stable-diffusion-v1-5" # You can change to your own model
6
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
7
- pipe = pipe.to("cuda")
8
-
9
- def generate(prompt):
10
- image = pipe(prompt).images[0]
11
- return image
12
-
13
- gr.Interface(
14
- fn=generate,
15
- inputs=gr.Textbox(label="Enter your prompt"),
16
- outputs=gr.Image(type="pil"),
17
- title="🎨 AI Image Generator",
18
- description="Enter a prompt to generate images using Stable Diffusion",
19
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Sample population data (you can use a CSV instead)
6
+ data = {
7
+ "Country": ["India", "China", "USA", "Indonesia", "Brazil"],
8
+ "Population": [1400000000, 1410000000, 331000000, 273000000, 213000000]
9
+ }
10
+ df = pd.DataFrame(data)
11
+
12
+ def plot_chart(countries, chart_type):
13
+ filtered_df = df[df["Country"].isin(countries)]
14
+ plt.figure(figsize=(8, 5))
15
+
16
+ if chart_type == "Bar":
17
+ plt.bar(filtered_df["Country"], filtered_df["Population"], color="skyblue")
18
+ plt.ylabel("Population")
19
+ else: # Pie chart
20
+ plt.pie(filtered_df["Population"], labels=filtered_df["Country"], autopct="%1.1f%%")
21
+
22
+ plt.title("Population by Country")
23
+ plt.tight_layout()
24
+ return plt
25
+
26
+ country_choices = df["Country"].tolist()
27
+
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("## 🌍 World Population Chart")
30
+ with gr.Row():
31
+ country_select = gr.CheckboxGroup(label="Select Countries", choices=country_choices, value=["India", "China"])
32
+ chart_type = gr.Radio(label="Chart Type", choices=["Bar", "Pie"], value="Bar")
33
+ output = gr.Plot()
34
+
35
+ country_select.change(plot_chart, inputs=[country_select, chart_type], outputs=output)
36
+ chart_type.change(plot_chart, inputs=[country_select, chart_type], outputs=output)
37
+
38
+ demo.launch()
39
+