Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from mlx_vlm import load, generate
|
| 3 |
+
|
| 4 |
+
# 1. This line loads the model from Hugging Face into the Space's memory
|
| 5 |
+
model, processor = load("mlx-community/gemma-4-e4b-it-8bit")
|
| 6 |
+
|
| 7 |
+
# 2. This is the function that talks to the AI
|
| 8 |
+
def chat_with_ai(image, prompt):
|
| 9 |
+
# It takes your picture and your question and gives back an answer
|
| 10 |
+
output = generate(model, processor, image, prompt, max_tokens=100)
|
| 11 |
+
return output
|
| 12 |
+
|
| 13 |
+
# 3. This builds the actual website you see
|
| 14 |
+
demo = gr.Interface(
|
| 15 |
+
fn=chat_with_ai,
|
| 16 |
+
inputs=[gr.Image(type="pil"), gr.Textbox(label="Ask about the image")],
|
| 17 |
+
outputs="text"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# 4. This starts the website!
|
| 21 |
+
demo.launch()
|