Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,30 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
from PIL import Image
|
| 4 |
-
from transformers import pipeline, AutoModel
|
| 5 |
|
| 6 |
-
#
|
| 7 |
pipe = pipeline("image-text-to-text", model="deepseek-ai/deepseek-vl2-small", trust_remote_code=True)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
image_path = image_path.replace("\\", "/")
|
| 16 |
-
image = Image.open(image_path).convert("RGB")
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
if __name__ == "__main__":
|
| 24 |
-
|
| 25 |
-
test_image = "sample_img2.JPG" # Ensure this image exists in the same folder
|
| 26 |
-
prompt = "Describe this image."
|
| 27 |
-
|
| 28 |
-
# Run prediction
|
| 29 |
-
output = predict(test_image, prompt)
|
| 30 |
-
print("Generated Response:", output)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load the model pipeline
|
| 5 |
pipe = pipeline("image-text-to-text", model="deepseek-ai/deepseek-vl2-small", trust_remote_code=True)
|
| 6 |
|
| 7 |
+
def chatbot(user_input):
|
| 8 |
+
"""
|
| 9 |
+
Function to process user input using the DeepSeek-VL2-Small model.
|
| 10 |
+
"""
|
| 11 |
+
messages = [{"role": "user", "content": user_input}]
|
| 12 |
+
response = pipe(messages)
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
if isinstance(response, list) and len(response) > 0:
|
| 15 |
+
return response[0]["generated_text"] # Extract response text
|
| 16 |
+
else:
|
| 17 |
+
return "No response received."
|
| 18 |
+
|
| 19 |
+
# Create a Gradio interface
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=chatbot,
|
| 22 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask something..."),
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="DeepSeek-VL2 Chatbot",
|
| 25 |
+
description="Ask questions and get AI-generated responses using DeepSeek-VL2-Small."
|
| 26 |
+
)
|
| 27 |
|
| 28 |
+
# Launch the Gradio app
|
| 29 |
if __name__ == "__main__":
|
| 30 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|