Spaces:
Running
Running
DeepSeek-V4.1-Flash image description workflow (gradio 6.26.0)
Browse files- .gitignore +2 -0
- README.md +1 -1
- requirements.txt +1 -0
- run.py +33 -3
- workflow.json +1 -1
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv/
|
| 2 |
+
__pycache__/
|
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: ⚡
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 6.
|
| 8 |
app_file: run.py
|
| 9 |
pinned: false
|
| 10 |
hf_oauth: true
|
|
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.26.0
|
| 8 |
app_file: run.py
|
| 9 |
pinned: false
|
| 10 |
hf_oauth: true
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
openai
|
run.py
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from openai import OpenAI
|
| 4 |
|
| 5 |
+
client = OpenAI(
|
| 6 |
+
base_url="https://router.huggingface.co/v1",
|
| 7 |
+
api_key=os.environ["HF_TOKEN"],
|
| 8 |
+
)
|
| 9 |
|
| 10 |
+
|
| 11 |
+
def describe_image(image_url: str, prompt: str) -> str:
|
| 12 |
+
"""Stream a one-sentence description of an image from DeepSeek-V4.1-Flash."""
|
| 13 |
+
stream = client.chat.completions.create(
|
| 14 |
+
model="deepseek-ai/DeepSeek-V4.1-Flash:novita",
|
| 15 |
+
messages=[
|
| 16 |
+
{
|
| 17 |
+
"role": "user",
|
| 18 |
+
"content": [
|
| 19 |
+
{"type": "text", "text": prompt},
|
| 20 |
+
{"type": "image_url", "image_url": {"url": image_url}},
|
| 21 |
+
],
|
| 22 |
+
}
|
| 23 |
+
],
|
| 24 |
+
stream=True,
|
| 25 |
+
)
|
| 26 |
+
output = ""
|
| 27 |
+
for chunk in stream:
|
| 28 |
+
if chunk.choices and chunk.choices[0].delta.content:
|
| 29 |
+
output += chunk.choices[0].delta.content
|
| 30 |
+
return output
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
gr.Workflow(
|
| 34 |
+
bind={"Describe Image": describe_image},
|
| 35 |
+
graph="workflow.json",
|
| 36 |
+
).launch()
|
workflow.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"schema_version":"2","name":"
|
|
|
|
| 1 |
+
{"schema_version":"2","name":"DeepSeek Image Describer","references":[{"id":"ref_image_url","label":"Image URL","role":"reference","asset_type":"text","inputs":[{"id":"in","label":"Text","type":"text"}],"outputs":[{"id":"out","label":"Text","type":"text"}],"data":{"out":""},"width":200},{"id":"ref_prompt","label":"Prompt","role":"reference","asset_type":"text","inputs":[{"id":"in","label":"Text","type":"text"}],"outputs":[{"id":"out","label":"Text","type":"text"}],"data":{"out":""},"width":200}],"operators":[{"id":"op_describe","label":"Describe Image","role":"operator","kind":"fn","fn":"Describe Image","inputs":[{"id":"in_image_url","label":"image_url","type":"text","required":true},{"id":"in_prompt","label":"prompt","type":"text","required":true}],"outputs":[{"id":"out_0","label":"output","type":"text","output_index":0}],"data":{},"width":200}],"subjects":[{"id":"sub_description","label":"Description","role":"subject","asset_type":"text","inputs":[{"id":"in","label":"Text","type":"text"}],"outputs":[{"id":"out","label":"Text","type":"text"}],"data":{"in":""},"width":200}],"edges":[{"id":"e1","from_node_id":"ref_image_url","from_port_id":"out","to_node_id":"op_describe","to_port_id":"in_image_url","type":"text"},{"id":"e2","from_node_id":"ref_prompt","from_port_id":"out","to_node_id":"op_describe","to_port_id":"in_prompt","type":"text"},{"id":"e3","from_node_id":"op_describe","from_port_id":"out_0","to_node_id":"sub_description","to_port_id":"in","type":"text"}]}
|