khurrameycon commited on
Commit
05271e3
·
verified ·
1 Parent(s): 832e593

commented few lines

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -32,29 +32,29 @@ model = MllamaForConditionalGeneration.from_pretrained(
32
  model.to(device)
33
  processor = AutoProcessor.from_pretrained(model_name, use_auth_token=HF_TOKEN)
34
 
35
- @spaces.GPU # Use the free GPU provided by Hugging Face Spaces
36
- def predict(image, text):
37
- # Prepare the input messages
38
- messages = [
39
- {"role": "user", "content": [
40
- {"type": "image"}, # Specify that an image is provided
41
- {"type": "text", "text": text} # Add the user-provided text input
42
- ]}
43
- ]
44
 
45
- # Create the input text using the processor's chat template
46
- input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
47
 
48
- # Process the inputs and move to the appropriate device
49
- inputs = processor(image, input_text, return_tensors="pt").to(device)
50
 
51
- # Generate a response from the model
52
- outputs = model.generate(**inputs, max_new_tokens=100)
53
 
54
- # Decode the output to return the final response
55
- response = processor.decode(outputs[0], skip_special_tokens=True)
56
- return response
57
-
58
  def predict_text(text):
59
  # Prepare the input messages
60
  messages = [{"role": "user", "content": [{"type": "text", "text": text}]}]
 
32
  model.to(device)
33
  processor = AutoProcessor.from_pretrained(model_name, use_auth_token=HF_TOKEN)
34
 
35
+ # @spaces.GPU # Use the free GPU provided by Hugging Face Spaces
36
+ # def predict(image, text):
37
+ # # Prepare the input messages
38
+ # messages = [
39
+ # {"role": "user", "content": [
40
+ # {"type": "image"}, # Specify that an image is provided
41
+ # {"type": "text", "text": text} # Add the user-provided text input
42
+ # ]}
43
+ # ]
44
 
45
+ # # Create the input text using the processor's chat template
46
+ # input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
47
 
48
+ # # Process the inputs and move to the appropriate device
49
+ # inputs = processor(image, input_text, return_tensors="pt").to(device)
50
 
51
+ # # Generate a response from the model
52
+ # outputs = model.generate(**inputs, max_new_tokens=100)
53
 
54
+ # # Decode the output to return the final response
55
+ # response = processor.decode(outputs[0], skip_special_tokens=True)
56
+ # return response
57
+ # @spaces.GPU
58
  def predict_text(text):
59
  # Prepare the input messages
60
  messages = [{"role": "user", "content": [{"type": "text", "text": text}]}]