Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -82,42 +82,46 @@ if uploaded_file is not None:
|
|
82 |
# Text query input
|
83 |
text_query = st.text_input("Enter your query about the image:")
|
84 |
|
|
|
|
|
85 |
if text_query:
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
121 |
|
122 |
# Display results
|
123 |
st.subheader("Results:")
|
|
|
82 |
# Text query input
|
83 |
text_query = st.text_input("Enter your query about the image:")
|
84 |
|
85 |
+
max_new_tokens = st.slider("Max new tokens for response", min_value=100, max_value=1000, value=100, step=10)
|
86 |
+
|
87 |
if text_query:
|
88 |
+
with st.spinner(
|
89 |
+
f'Processing your query... This may take a while due to CPU processing. Generating up to {max_new_tokens} tokens.'):
|
90 |
+
# Perform RAG search
|
91 |
+
results = RAG.search(text_query, k=2)
|
92 |
+
|
93 |
+
# Process with Qwen2VL model
|
94 |
+
messages = [
|
95 |
+
{
|
96 |
+
"role": "user",
|
97 |
+
"content": [
|
98 |
+
{
|
99 |
+
"type": "image",
|
100 |
+
"image": image_path,
|
101 |
+
},
|
102 |
+
{"type": "text", "text": text_query},
|
103 |
+
],
|
104 |
+
}
|
105 |
+
]
|
106 |
+
text = processor.apply_chat_template(
|
107 |
+
messages, tokenize=False, add_generation_prompt=True
|
108 |
+
)
|
109 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
110 |
+
inputs = processor(
|
111 |
+
text=[text],
|
112 |
+
images=image_inputs,
|
113 |
+
videos=video_inputs,
|
114 |
+
padding=True,
|
115 |
+
return_tensors="pt",
|
116 |
+
)
|
117 |
+
inputs = inputs.to(device)
|
118 |
+
generated_ids = model.generate(**inputs, max_new_tokens=max_new_tokens) # Using the slider value here
|
119 |
+
generated_ids_trimmed = [
|
120 |
+
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
121 |
+
]
|
122 |
+
output_text = processor.batch_decode(
|
123 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
124 |
+
)
|
125 |
|
126 |
# Display results
|
127 |
st.subheader("Results:")
|