Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
97 |
image_bytes = io.BytesIO()
|
98 |
image.save(image_bytes, format='PNG')
|
99 |
image_bytes.seek(0)
|
100 |
|
101 |
-
#
|
102 |
response = ""
|
103 |
|
104 |
-
for
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
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 |
+
|