maahin commited on
Commit
1348715
·
verified ·
1 Parent(s): 5a53f59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -22
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import os
2
  import streamlit as st
3
- from PIL import Image, ImageDraw
4
  import torch
5
- import re
6
  from transformers import PaliGemmaProcessor, PaliGemmaForConditionalGeneration
7
 
8
  # Get Hugging Face API key from environment variables
@@ -47,7 +46,7 @@ if uploaded_file:
47
  # User input for task selection
48
  task = st.selectbox(
49
  "Select a task:",
50
- ["Generate a caption", "Answer a question", "Detect objects", "Segment"]
51
  )
52
 
53
  # User prompt
@@ -63,22 +62,4 @@ if uploaded_file:
63
  generation = generation[0][input_len:] # Remove input tokens from output
64
  answer = processor.decode(generation, skip_special_tokens=True)
65
 
66
- # Function to highlight <segXXX> values in yellow
67
- def highlight_segments(text):
68
- return re.sub(r"(<seg\d+>)", r'<span style="background-color:yellow; padding:3px; border-radius:3px;">\1</span>', text)
69
-
70
- # Display output based on task selection
71
- if task == "Segment":
72
- highlighted_answer = highlight_segments(answer)
73
- st.markdown(f'<p style="font-size:16px;">✅ Result: {highlighted_answer}</p>', unsafe_allow_html=True)
74
- else:
75
- st.success(f"✅ Result: {answer}")
76
-
77
- # Draw red bounding box for object detection
78
- if task == "Detect objects":
79
- draw = ImageDraw.Draw(image)
80
- # Placeholder: Replace with actual detection logic
81
- boxes = [(50, 50, 200, 200), (250, 100, 400, 300)] # Example boxes
82
- for box in boxes:
83
- draw.rectangle(box, outline="red", width=3)
84
- st.image(image, caption="Detected Objects", use_container_width=True)
 
1
  import os
2
  import streamlit as st
3
+ from PIL import Image
4
  import torch
 
5
  from transformers import PaliGemmaProcessor, PaliGemmaForConditionalGeneration
6
 
7
  # Get Hugging Face API key from environment variables
 
46
  # User input for task selection
47
  task = st.selectbox(
48
  "Select a task:",
49
+ ["Generate a caption", "Answer a question", "Detect objects"]
50
  )
51
 
52
  # User prompt
 
62
  generation = generation[0][input_len:] # Remove input tokens from output
63
  answer = processor.decode(generation, skip_special_tokens=True)
64
 
65
+ st.success(f"✅ Result: {answer}")