Pavithiran commited on
Commit
cff7963
·
verified ·
1 Parent(s): 1028c33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -68,9 +68,6 @@ from huggingface_hub import InferenceClient
68
  from PIL import Image
69
  import io
70
 
71
- """
72
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
73
- """
74
  client = InferenceClient("meta-llama/Llama-3.2-11B-Vision-Instruct")
75
 
76
  def respond(
@@ -82,7 +79,6 @@ def respond(
82
  top_p,
83
  image: Image
84
  ):
85
- # Prepare messages
86
  messages = [{"role": "system", "content": system_message}]
87
 
88
  for val in history:
@@ -93,27 +89,23 @@ def respond(
93
 
94
  messages.append({"role": "user", "content": message})
95
 
96
- # Convert the image to bytes for HuggingFace API processing
97
  image_bytes = io.BytesIO()
98
  image.save(image_bytes, format='PNG')
99
  image_bytes.seek(0)
100
 
101
- # Make the API call with the image and messages
102
  response = ""
103
 
104
- for result in client.chat_completion(
105
- messages,
106
- image=image_bytes,
107
- max_tokens=max_tokens,
108
- stream=True,
109
- temperature=temperature,
110
- top_p=top_p,
111
- ):
112
- token = result.choices[0].delta.content
113
- response += token
114
- yield response
115
-
116
- # Gradio demo for ChatInterface with image support
117
  demo = gr.ChatInterface(
118
  respond,
119
  additional_inputs=[
@@ -134,3 +126,4 @@ demo = gr.ChatInterface(
134
  if __name__ == "__main__":
135
  demo.launch()
136
 
 
 
68
  from PIL import Image
69
  import io
70
 
 
 
 
71
  client = InferenceClient("meta-llama/Llama-3.2-11B-Vision-Instruct")
72
 
73
  def respond(
 
79
  top_p,
80
  image: Image
81
  ):
 
82
  messages = [{"role": "system", "content": system_message}]
83
 
84
  for val in history:
 
89
 
90
  messages.append({"role": "user", "content": message})
91
 
92
+ # Convert image to the format expected by the model
93
  image_bytes = io.BytesIO()
94
  image.save(image_bytes, format='PNG')
95
  image_bytes.seek(0)
96
 
97
+ # Use a different method for image inputs if chat_completion does not support it
98
  response = ""
99
 
100
+ # Modify here to use the correct API for image + text queries (check model docs)
101
+ response_data = client.text2image(images=image_bytes, text=message) # example method; adjust according to actual API
102
+
103
+ # Process the response (if any) from the image model
104
+ for result in response_data:
105
+ response += result['text'] # or adjust based on response format
106
+
107
+ return response
108
+
 
 
 
 
109
  demo = gr.ChatInterface(
110
  respond,
111
  additional_inputs=[
 
126
  if __name__ == "__main__":
127
  demo.launch()
128
 
129
+