WaysAheadGlobal commited on
Commit
a3766e8
Β·
verified Β·
1 Parent(s): 49abead

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -2,11 +2,11 @@ import streamlit as st
2
  from transformers import pipeline
3
  from PIL import Image
4
 
5
- # Page setup
6
- st.set_page_config(page_title="TinyLLaVA - Snapshot", layout="centered")
7
- st.title("πŸ“· TinyLLaVA - Snapshot Q&A (Hugging Face Spaces)")
8
 
9
- # Load TinyLLaVA
10
  pipe = pipeline(
11
  task="image-to-text",
12
  model="bczhou/tiny-llava-v1-hf",
@@ -14,21 +14,19 @@ pipe = pipeline(
14
  device_map="cpu"
15
  )
16
 
17
- # Camera input
18
- captured_image = st.camera_input("πŸ“Έ Take a photo")
19
 
20
- # Prompt
21
- prompt = st.text_input("πŸ’¬ What do you want to ask about this image?", value="Describe this scene.")
22
 
23
- # Run when both available
24
- if captured_image and prompt:
25
- img = Image.open(captured_image).convert("RGB")
26
  st.image(img, caption="Your Snapshot", use_column_width=True)
27
 
28
- # Format query
29
  query = f"USER: <image>\n{prompt}\nASSISTANT:"
30
-
31
- with st.spinner("TinyLLaVA is thinking..."):
32
  result = pipe(query, img)
33
  answer = result[0]["generated_text"]
34
 
 
2
  from transformers import pipeline
3
  from PIL import Image
4
 
5
+ # Page config
6
+ st.set_page_config(page_title="TinyLLaVA Snapshot Q&A", layout="centered")
7
+ st.title("πŸ“Έ TinyLLaVA - Snapshot Q&A (Hugging Face Spaces)")
8
 
9
+ # Load TinyLLaVA pipeline
10
  pipe = pipeline(
11
  task="image-to-text",
12
  model="bczhou/tiny-llava-v1-hf",
 
14
  device_map="cpu"
15
  )
16
 
17
+ # Always visible camera input
18
+ image = st.camera_input("πŸ“· Take a snapshot")
19
 
20
+ # Prompt text input
21
+ prompt = st.text_input("πŸ’¬ Your question:", value="Describe this scene.")
22
 
23
+ # If both present, run inference
24
+ if image is not None and prompt:
25
+ img = Image.open(image).convert("RGB")
26
  st.image(img, caption="Your Snapshot", use_column_width=True)
27
 
 
28
  query = f"USER: <image>\n{prompt}\nASSISTANT:"
29
+ with st.spinner("TinyLLaVA is generating..."):
 
30
  result = pipe(query, img)
31
  answer = result[0]["generated_text"]
32