Spaces:
Sleeping
Sleeping
api start
Browse files- app.py +42 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# pipeline as high level
|
| 5 |
+
pipe = pipeline("image-text-to-text", model="HuggingFaceM4/Idefics3-8B-Llama3")
|
| 6 |
+
|
| 7 |
+
SYSTEM_PROMPT = f"""
|
| 8 |
+
You are a image vibe AI and your job is to help users capture the energy
|
| 9 |
+
and aesthetic of the entire scene - mainly what the people are doing in their background.
|
| 10 |
+
Respond only in one sentence and don't elaborate.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
def get_image_vibe(image):
|
| 14 |
+
if image is None:
|
| 15 |
+
return "No image provided."
|
| 16 |
+
|
| 17 |
+
messages = [
|
| 18 |
+
{
|
| 19 |
+
"role": "system",
|
| 20 |
+
"content": [
|
| 21 |
+
{"type": "text", "text": SYSTEM_PROMPT}
|
| 22 |
+
]
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"role": "user",
|
| 26 |
+
"content": [
|
| 27 |
+
{"type": "image", "image": image}
|
| 28 |
+
]
|
| 29 |
+
}
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
result = pipe(messages)
|
| 33 |
+
return result[0]['generated_text']
|
| 34 |
+
|
| 35 |
+
# api w/ gradio
|
| 36 |
+
api = gr.Interface(
|
| 37 |
+
fn=get_image_vibe,
|
| 38 |
+
inputs=gr.Image(type="filepath", label="Input Image"),
|
| 39 |
+
outputs="text"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
api.launch(show_api=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
gradio
|
| 3 |
+
torch
|