Anupam202224 commited on
Commit
f6b3835
·
verified ·
1 Parent(s): 852ebe2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -7,9 +7,6 @@ import torch
7
  import matplotlib.pyplot as plt
8
  import seaborn as sns
9
 
10
- # Optional: Uncomment the following lines if you plan to use a gated model in the future
11
- # from huggingface_hub import login
12
-
13
  # Define constants
14
  MODEL_NAME = "gpt2" # Publicly accessible model suitable for CPU
15
  FIGURES_DIR = "./figures"
@@ -20,7 +17,7 @@ EXAMPLE_FILE = os.path.join(EXAMPLE_DIR, "titanic.csv")
20
  os.makedirs(FIGURES_DIR, exist_ok=True)
21
  os.makedirs(EXAMPLE_DIR, exist_ok=True)
22
 
23
- # Download the Titanic dataset if it doesn't exist
24
  if not os.path.isfile(EXAMPLE_FILE):
25
  print("Downloading the Titanic dataset for examples...")
26
  try:
@@ -191,7 +188,16 @@ def interact_with_agent(file_input, additional_notes):
191
  for image_path in visualization_paths:
192
  # Ensure the image path is valid before attempting to display
193
  if os.path.isfile(image_path):
194
- messages.append({"role": "assistant", "content": f"![{os.path.basename(image_path)}]({image_path})"})
 
 
 
 
 
 
 
 
 
195
  else:
196
  messages.append({"role": "assistant", "content": f"⚠️ Unable to find image: {image_path}"})
197
 
 
7
  import matplotlib.pyplot as plt
8
  import seaborn as sns
9
 
 
 
 
10
  # Define constants
11
  MODEL_NAME = "gpt2" # Publicly accessible model suitable for CPU
12
  FIGURES_DIR = "./figures"
 
17
  os.makedirs(FIGURES_DIR, exist_ok=True)
18
  os.makedirs(EXAMPLE_DIR, exist_ok=True)
19
 
20
+ # Download the Titanic dataset if it doesn't exist (only for local runs)
21
  if not os.path.isfile(EXAMPLE_FILE):
22
  print("Downloading the Titanic dataset for examples...")
23
  try:
 
188
  for image_path in visualization_paths:
189
  # Ensure the image path is valid before attempting to display
190
  if os.path.isfile(image_path):
191
+ # To display images in Gradio Chatbot, use the 'gr.Image' component
192
+ # However, since we're using 'type="messages"', we need to embed images via Markdown
193
+ # Gradio supports Markdown image embedding
194
+ image_filename = os.path.basename(image_path)
195
+ # Convert image path to relative path if necessary
196
+ # For Spaces, images should be in the repository
197
+ messages.append({
198
+ "role": "assistant",
199
+ "content": f"![{image_filename}]({image_path})"
200
+ })
201
  else:
202
  messages.append({"role": "assistant", "content": f"⚠️ Unable to find image: {image_path}"})
203