VinitT commited on
Commit
5b0226f
·
verified ·
1 Parent(s): f8d8f82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -23
app.py CHANGED
@@ -66,11 +66,6 @@ if uploaded_files:
66
  st.error("Unsupported file type.")
67
  continue
68
 
69
- # Ensure the image is loaded correctly
70
- if image is None:
71
- st.error("Failed to load the image.")
72
- continue
73
-
74
  messages = [
75
  {
76
  "role": "user",
@@ -99,24 +94,19 @@ if uploaded_files:
99
  inputs = inputs.to(device) # Ensure inputs are on the same device as the model
100
 
101
  # Inference: Generation of the output
102
- try:
103
- generated_ids = model.generate(**inputs, max_new_tokens=512)
104
- generated_ids_trimmed = [
105
- out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
106
- ]
107
- output_text = processor.batch_decode(
108
- generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
109
- )
110
-
111
- st.write("Description:")
112
- st.write(output_text[0])
113
-
114
- # Append the output text to the list
115
- all_output_texts.append(output_text[0])
116
-
117
- except Exception as e:
118
- st.error(f"Error during generation: {e}")
119
- continue
120
 
121
  # Clear memory after processing each file
122
  del image, inputs, generated_ids, generated_ids_trimmed, output_text
 
66
  st.error("Unsupported file type.")
67
  continue
68
 
 
 
 
 
 
69
  messages = [
70
  {
71
  "role": "user",
 
94
  inputs = inputs.to(device) # Ensure inputs are on the same device as the model
95
 
96
  # Inference: Generation of the output
97
+ generated_ids = model.generate(**inputs, max_new_tokens=512)
98
+ generated_ids_trimmed = [
99
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
100
+ ]
101
+ output_text = processor.batch_decode(
102
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
103
+ )
104
+
105
+ st.write("Description:")
106
+ st.write(output_text[0])
107
+
108
+ # Append the output text to the list
109
+ all_output_texts.append(output_text[0])
 
 
 
 
 
110
 
111
  # Clear memory after processing each file
112
  del image, inputs, generated_ids, generated_ids_trimmed, output_text