Ari commited on
Commit
3d081a7
·
1 Parent(s): 60be843

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -7
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
2
  import openai
3
  import pandas as pd
 
 
4
 
5
  # Load your CSV file
6
  data = pd.read_csv("RR.csv")
@@ -29,22 +31,46 @@ def get_insights(question):
29
  answer = query_gpt(prompt)
30
  return answer
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  markdown_data = f"Mock Dataset For GDS Social MBR :\n```\n{data.head(10).to_string(index=False)}\n```\n"
34
 
 
 
 
 
 
 
35
  iface = gr.Interface(
36
- fn=get_insights,
37
  inputs=[
38
  gr.inputs.Textbox(lines=2, label="Enter your question"),
 
 
 
 
 
39
  ],
40
- outputs="text",
41
- title="GPT-powered Q&A",
42
  description=markdown_data,
43
  examples=[
44
- ("Are there any trends or seasonality in calls handled?",),
45
- ("Are there any patterns that suggest a need for additional staff during specific periods?",),
46
- ("Can you identify any months with a significantly higher or lower number of calls handled compared to the overall average?",),
47
- ("Are there any patterns that suggest a need for additional staff during specific periods?",),
 
48
  ],
49
  allow_screenshot=False,
50
  theme="compact",
 
1
  import gradio as gr
2
  import openai
3
  import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+ import seaborn as sns
6
 
7
  # Load your CSV file
8
  data = pd.read_csv("RR.csv")
 
31
  answer = query_gpt(prompt)
32
  return answer
33
 
34
+ def create_visualization_report():
35
+ # Customize your visualizations, for example:
36
+ # Plotting a heatmap to show correlations between columns
37
+ fig, ax = plt.subplots(figsize=(10, 8))
38
+ sns.heatmap(data.corr(), annot=True, fmt=".2f", cmap="coolwarm", ax=ax)
39
+ plt.title("Correlation Heatmap")
40
+
41
+ # Save the visualization to a file
42
+ fig.savefig("visualization_report.png")
43
+ plt.close(fig)
44
+
45
+ # Return the saved file
46
+ return "visualization_report.png"
47
 
48
  markdown_data = f"Mock Dataset For GDS Social MBR :\n```\n{data.head(10).to_string(index=False)}\n```\n"
49
 
50
+ def gradio_wrapper(question, generate_visualization):
51
+ if generate_visualization:
52
+ return create_visualization_report()
53
+ else:
54
+ return get_insights(question)
55
+
56
  iface = gr.Interface(
57
+ fn=gradio_wrapper,
58
  inputs=[
59
  gr.inputs.Textbox(lines=2, label="Enter your question"),
60
+ gr.inputs.Checkbox(label="Generate Visualization Report"),
61
+ ],
62
+ outputs=[
63
+ gr.outputs.Textbox(label="Answer"),
64
+ gr.outputs.Image(type="file", label="Visualization Report"),
65
  ],
66
+ title="GPT-powered Q&A with Visualization",
 
67
  description=markdown_data,
68
  examples=[
69
+ ("Are there any trends or seasonality in calls handled?", False),
70
+ ("Are there any patterns that suggest a need for additional staff during specific periods?", False),
71
+ ("Can you identify any months with a significantly higher or lower number of calls handled compared to the overall average?", False),
72
+ ("Are there any patterns that suggest a need for additional staff during specific periods?", False),
73
+ ("", True),
74
  ],
75
  allow_screenshot=False,
76
  theme="compact",