dhruvsaxena11 commited on
Commit
3e99fcf
Β·
verified Β·
1 Parent(s): e219358

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -63,20 +63,20 @@ def plot_sensor_data(df):
63
  plt.close(fig)
64
  return Image.open(fig_path)
65
 
66
- pipe = pipeline("visual-question-answering", model="ybelkada/blip2-opt-2.7b-fp16-sharded")
67
 
68
  # Generate recommendations
69
  def analyze_data(image, plot_path):
70
  try:
71
- # Ensure the image is a PIL object
72
  if isinstance(image, np.ndarray):
73
  image = Image.fromarray(image)
74
 
75
  # Damage analysis
76
- damage_output = pipe(image=image, question="Describe any visible damage in the image.")[0]['answer'] if image else "No image uploaded."
77
 
78
  # Graph analysis
79
- graph_analysis = pipe(image=plot_path, question="What anomalies or patterns can be observed?")[0]['answer']
80
 
81
  # Recommendations
82
  recommendations = f"Recommendations based on analysis:\n\n1. {graph_analysis}\n\n2. {damage_output}"
@@ -85,7 +85,6 @@ def analyze_data(image, plot_path):
85
  except Exception as e:
86
  return f"Error occurred: {str(e)}", None, None
87
 
88
-
89
  # Gradio UI
90
  with gr.Blocks(css=".output-text { font-family: 'Arial'; color: #222; font-size: 1rem; }") as app:
91
  gr.Markdown("# πŸš— Car Health Report Generation using Generative AI")
 
63
  plt.close(fig)
64
  return Image.open(fig_path)
65
 
66
+ pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
67
 
68
  # Generate recommendations
69
  def analyze_data(image, plot_path):
70
  try:
71
+ # Ensure image is a PIL object
72
  if isinstance(image, np.ndarray):
73
  image = Image.fromarray(image)
74
 
75
  # Damage analysis
76
+ damage_output = pipe(inputs=image)[0]['generated_text'] if image else "No image uploaded."
77
 
78
  # Graph analysis
79
+ graph_analysis = pipe(inputs=plot_path)[0]['generated_text']
80
 
81
  # Recommendations
82
  recommendations = f"Recommendations based on analysis:\n\n1. {graph_analysis}\n\n2. {damage_output}"
 
85
  except Exception as e:
86
  return f"Error occurred: {str(e)}", None, None
87
 
 
88
  # Gradio UI
89
  with gr.Blocks(css=".output-text { font-family: 'Arial'; color: #222; font-size: 1rem; }") as app:
90
  gr.Markdown("# πŸš— Car Health Report Generation using Generative AI")