clayton07 commited on
Commit
b5ba0b7
·
verified ·
1 Parent(s): ca3b38f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -35
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
- # Perform RAG search
87
- results = RAG.search(text_query, k=2)
88
-
89
- # Process with Qwen2VL model
90
- messages = [
91
- {
92
- "role": "user",
93
- "content": [
94
- {
95
- "type": "image",
96
- "image": image_path,
97
- },
98
- {"type": "text", "text": text_query},
99
- ],
100
- }
101
- ]
102
- text = processor.apply_chat_template(
103
- messages, tokenize=False, add_generation_prompt=True
104
- )
105
- image_inputs, video_inputs = process_vision_info(messages)
106
- inputs = processor(
107
- text=[text],
108
- images=image_inputs,
109
- videos=video_inputs,
110
- padding=True,
111
- return_tensors="pt",
112
- )
113
- inputs = inputs.to(device)
114
- generated_ids = model.generate(**inputs, max_new_tokens=100)
115
- generated_ids_trimmed = [
116
- out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
117
- ]
118
- output_text = processor.batch_decode(
119
- generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
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:")