Spaces:
Runtime error
Runtime error
first
Browse files- .idea/.gitignore +3 -0
- .idea/AskMoondream.iml +8 -0
- .idea/inspectionProfiles/Project_Default.xml +207 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +59 -0
- requirements.txt +4 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/AskMoondream.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="inheritedJdk" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
5 |
+
<option name="ignoredPackages">
|
6 |
+
<value>
|
7 |
+
<list size="187">
|
8 |
+
<item index="0" class="java.lang.String" itemvalue="importlib-metadata" />
|
9 |
+
<item index="1" class="java.lang.String" itemvalue="chromadb" />
|
10 |
+
<item index="2" class="java.lang.String" itemvalue="tzlocal" />
|
11 |
+
<item index="3" class="java.lang.String" itemvalue="scikit-learn" />
|
12 |
+
<item index="4" class="java.lang.String" itemvalue="tabulate" />
|
13 |
+
<item index="5" class="java.lang.String" itemvalue="opentelemetry-proto" />
|
14 |
+
<item index="6" class="java.lang.String" itemvalue="validators" />
|
15 |
+
<item index="7" class="java.lang.String" itemvalue="ufw" />
|
16 |
+
<item index="8" class="java.lang.String" itemvalue="pyth" />
|
17 |
+
<item index="9" class="java.lang.String" itemvalue="pycairo" />
|
18 |
+
<item index="10" class="java.lang.String" itemvalue="pycparser" />
|
19 |
+
<item index="11" class="java.lang.String" itemvalue="cmdtest" />
|
20 |
+
<item index="12" class="java.lang.String" itemvalue="PyGObject" />
|
21 |
+
<item index="13" class="java.lang.String" itemvalue="posthog" />
|
22 |
+
<item index="14" class="java.lang.String" itemvalue="distro-info" />
|
23 |
+
<item index="15" class="java.lang.String" itemvalue="pyasn1-modules" />
|
24 |
+
<item index="16" class="java.lang.String" itemvalue="systemd-python" />
|
25 |
+
<item index="17" class="java.lang.String" itemvalue="cliapp" />
|
26 |
+
<item index="18" class="java.lang.String" itemvalue="language-selector" />
|
27 |
+
<item index="19" class="java.lang.String" itemvalue="uvicorn" />
|
28 |
+
<item index="20" class="java.lang.String" itemvalue="pysimdjson" />
|
29 |
+
<item index="21" class="java.lang.String" itemvalue="terminado" />
|
30 |
+
<item index="22" class="java.lang.String" itemvalue="pydantic" />
|
31 |
+
<item index="23" class="java.lang.String" itemvalue="Werkzeug" />
|
32 |
+
<item index="24" class="java.lang.String" itemvalue="pyglet" />
|
33 |
+
<item index="25" class="java.lang.String" itemvalue="streamlit" />
|
34 |
+
<item index="26" class="java.lang.String" itemvalue="opentelemetry-api" />
|
35 |
+
<item index="27" class="java.lang.String" itemvalue="pinecone-client" />
|
36 |
+
<item index="28" class="java.lang.String" itemvalue="reportlab" />
|
37 |
+
<item index="29" class="java.lang.String" itemvalue="PyMuPDFb" />
|
38 |
+
<item index="30" class="java.lang.String" itemvalue="pexpect" />
|
39 |
+
<item index="31" class="java.lang.String" itemvalue="pypdf" />
|
40 |
+
<item index="32" class="java.lang.String" itemvalue="python-apt" />
|
41 |
+
<item index="33" class="java.lang.String" itemvalue="SecretStorage" />
|
42 |
+
<item index="34" class="java.lang.String" itemvalue="ubuntu-advantage-tools" />
|
43 |
+
<item index="35" class="java.lang.String" itemvalue="opentelemetry-util-http" />
|
44 |
+
<item index="36" class="java.lang.String" itemvalue="psutil" />
|
45 |
+
<item index="37" class="java.lang.String" itemvalue="openai" />
|
46 |
+
<item index="38" class="java.lang.String" itemvalue="pyxdg" />
|
47 |
+
<item index="39" class="java.lang.String" itemvalue="nvidia-cublas-cu12" />
|
48 |
+
<item index="40" class="java.lang.String" itemvalue="paramiko" />
|
49 |
+
<item index="41" class="java.lang.String" itemvalue="pydantic_core" />
|
50 |
+
<item index="42" class="java.lang.String" itemvalue="platformdirs" />
|
51 |
+
<item index="43" class="java.lang.String" itemvalue="referencing" />
|
52 |
+
<item index="44" class="java.lang.String" itemvalue="PyJWT" />
|
53 |
+
<item index="45" class="java.lang.String" itemvalue="netifaces" />
|
54 |
+
<item index="46" class="java.lang.String" itemvalue="nvidia-nvjitlink-cu12" />
|
55 |
+
<item index="47" class="java.lang.String" itemvalue="nvidia-cusparse-cu12" />
|
56 |
+
<item index="48" class="java.lang.String" itemvalue="pandocfilters" />
|
57 |
+
<item index="49" class="java.lang.String" itemvalue="py4j" />
|
58 |
+
<item index="50" class="java.lang.String" itemvalue="pyasn1" />
|
59 |
+
<item index="51" class="java.lang.String" itemvalue="jupyter-events" />
|
60 |
+
<item index="52" class="java.lang.String" itemvalue="nvidia-nccl-cu12" />
|
61 |
+
<item index="53" class="java.lang.String" itemvalue="sniffio" />
|
62 |
+
<item index="54" class="java.lang.String" itemvalue="websocket-client" />
|
63 |
+
<item index="55" class="java.lang.String" itemvalue="seaborn" />
|
64 |
+
<item index="56" class="java.lang.String" itemvalue="zipp" />
|
65 |
+
<item index="57" class="java.lang.String" itemvalue="prompt-toolkit" />
|
66 |
+
<item index="58" class="java.lang.String" itemvalue="xgboost" />
|
67 |
+
<item index="59" class="java.lang.String" itemvalue="together" />
|
68 |
+
<item index="60" class="java.lang.String" itemvalue="websockets" />
|
69 |
+
<item index="61" class="java.lang.String" itemvalue="pyarrow" />
|
70 |
+
<item index="62" class="java.lang.String" itemvalue="PyOpenGL" />
|
71 |
+
<item index="63" class="java.lang.String" itemvalue="ubuntu-drivers-common" />
|
72 |
+
<item index="64" class="java.lang.String" itemvalue="PyMuPDF" />
|
73 |
+
<item index="65" class="java.lang.String" itemvalue="scipy" />
|
74 |
+
<item index="66" class="java.lang.String" itemvalue="watchfiles" />
|
75 |
+
<item index="67" class="java.lang.String" itemvalue="tornado" />
|
76 |
+
<item index="68" class="java.lang.String" itemvalue="xkit" />
|
77 |
+
<item index="69" class="java.lang.String" itemvalue="nvidia-cudnn-cu12" />
|
78 |
+
<item index="70" class="java.lang.String" itemvalue="torch" />
|
79 |
+
<item index="71" class="java.lang.String" itemvalue="overrides" />
|
80 |
+
<item index="72" class="java.lang.String" itemvalue="toml" />
|
81 |
+
<item index="73" class="java.lang.String" itemvalue="opentelemetry-semantic-conventions" />
|
82 |
+
<item index="74" class="java.lang.String" itemvalue="pandas" />
|
83 |
+
<item index="75" class="java.lang.String" itemvalue="watchdog" />
|
84 |
+
<item index="76" class="java.lang.String" itemvalue="typing_extensions" />
|
85 |
+
<item index="77" class="java.lang.String" itemvalue="dbus-python" />
|
86 |
+
<item index="78" class="java.lang.String" itemvalue="olefile" />
|
87 |
+
<item index="79" class="java.lang.String" itemvalue="usb-creator" />
|
88 |
+
<item index="80" class="java.lang.String" itemvalue="opentelemetry-instrumentation" />
|
89 |
+
<item index="81" class="java.lang.String" itemvalue="traitlets" />
|
90 |
+
<item index="82" class="java.lang.String" itemvalue="protobuf" />
|
91 |
+
<item index="83" class="java.lang.String" itemvalue="ttystatus" />
|
92 |
+
<item index="84" class="java.lang.String" itemvalue="pygame" />
|
93 |
+
<item index="85" class="java.lang.String" itemvalue="threadpoolctl" />
|
94 |
+
<item index="86" class="java.lang.String" itemvalue="Brlapi" />
|
95 |
+
<item index="87" class="java.lang.String" itemvalue="duplicity" />
|
96 |
+
<item index="88" class="java.lang.String" itemvalue="python-dateutil" />
|
97 |
+
<item index="89" class="java.lang.String" itemvalue="roman" />
|
98 |
+
<item index="90" class="java.lang.String" itemvalue="pycups" />
|
99 |
+
<item index="91" class="java.lang.String" itemvalue="python-dotenv" />
|
100 |
+
<item index="92" class="java.lang.String" itemvalue="gym-maze" />
|
101 |
+
<item index="93" class="java.lang.String" itemvalue="PyPika" />
|
102 |
+
<item index="94" class="java.lang.String" itemvalue="nvidia-cusolver-cu12" />
|
103 |
+
<item index="95" class="java.lang.String" itemvalue="pyzmq" />
|
104 |
+
<item index="96" class="java.lang.String" itemvalue="polars" />
|
105 |
+
<item index="97" class="java.lang.String" itemvalue="pyparsing" />
|
106 |
+
<item index="98" class="java.lang.String" itemvalue="unattended-upgrades" />
|
107 |
+
<item index="99" class="java.lang.String" itemvalue="opentelemetry-instrumentation-asgi" />
|
108 |
+
<item index="100" class="java.lang.String" itemvalue="sympy" />
|
109 |
+
<item index="101" class="java.lang.String" itemvalue="uvloop" />
|
110 |
+
<item index="102" class="java.lang.String" itemvalue="triton" />
|
111 |
+
<item index="103" class="java.lang.String" itemvalue="setuptools-git" />
|
112 |
+
<item index="104" class="java.lang.String" itemvalue="opentelemetry-exporter-otlp-proto-grpc" />
|
113 |
+
<item index="105" class="java.lang.String" itemvalue="pulsar-client" />
|
114 |
+
<item index="106" class="java.lang.String" itemvalue="orjson" />
|
115 |
+
<item index="107" class="java.lang.String" itemvalue="opentelemetry-instrumentation-fastapi" />
|
116 |
+
<item index="108" class="java.lang.String" itemvalue="duckdb" />
|
117 |
+
<item index="109" class="java.lang.String" itemvalue="nvidia-nvtx-cu12" />
|
118 |
+
<item index="110" class="java.lang.String" itemvalue="streamlit-float" />
|
119 |
+
<item index="111" class="java.lang.String" itemvalue="widgetsnbextension" />
|
120 |
+
<item index="112" class="java.lang.String" itemvalue="gyp" />
|
121 |
+
<item index="113" class="java.lang.String" itemvalue="pyautogen" />
|
122 |
+
<item index="114" class="java.lang.String" itemvalue="webargs" />
|
123 |
+
<item index="115" class="java.lang.String" itemvalue="whatsapp-python" />
|
124 |
+
<item index="116" class="java.lang.String" itemvalue="miniworld" />
|
125 |
+
<item index="117" class="java.lang.String" itemvalue="defer" />
|
126 |
+
<item index="118" class="java.lang.String" itemvalue="pydeck" />
|
127 |
+
<item index="119" class="java.lang.String" itemvalue="ptyprocess" />
|
128 |
+
<item index="120" class="java.lang.String" itemvalue="SQLAlchemy" />
|
129 |
+
<item index="121" class="java.lang.String" itemvalue="opentelemetry-sdk" />
|
130 |
+
<item index="122" class="java.lang.String" itemvalue="pyspark" />
|
131 |
+
<item index="123" class="java.lang.String" itemvalue="wcwidth" />
|
132 |
+
<item index="124" class="java.lang.String" itemvalue="types-python-dateutil" />
|
133 |
+
<item index="125" class="java.lang.String" itemvalue="python-debian" />
|
134 |
+
<item index="126" class="java.lang.String" itemvalue="cupshelpers" />
|
135 |
+
<item index="127" class="java.lang.String" itemvalue="onnxruntime" />
|
136 |
+
<item index="128" class="java.lang.String" itemvalue="chroma-hnswlib" />
|
137 |
+
<item index="129" class="java.lang.String" itemvalue="rpds-py" />
|
138 |
+
<item index="130" class="java.lang.String" itemvalue="tomli" />
|
139 |
+
<item index="131" class="java.lang.String" itemvalue="louis" />
|
140 |
+
<item index="132" class="java.lang.String" itemvalue="urllib3" />
|
141 |
+
<item index="133" class="java.lang.String" itemvalue="faiss-gpu" />
|
142 |
+
<item index="134" class="java.lang.String" itemvalue="sseclient-py" />
|
143 |
+
<item index="135" class="java.lang.String" itemvalue="typer" />
|
144 |
+
<item index="136" class="java.lang.String" itemvalue="pandasai" />
|
145 |
+
<item index="137" class="java.lang.String" itemvalue="parso" />
|
146 |
+
<item index="138" class="java.lang.String" itemvalue="prometheus-client" />
|
147 |
+
<item index="139" class="java.lang.String" itemvalue="pyth3" />
|
148 |
+
<item index="140" class="java.lang.String" itemvalue="pillow" />
|
149 |
+
<item index="141" class="java.lang.String" itemvalue="xdg" />
|
150 |
+
<item index="142" class="java.lang.String" itemvalue="command-not-found" />
|
151 |
+
<item index="143" class="java.lang.String" itemvalue="opentelemetry-exporter-otlp-proto-common" />
|
152 |
+
<item index="144" class="java.lang.String" itemvalue="accelerate" />
|
153 |
+
<item index="145" class="java.lang.String" itemvalue="diffusers" />
|
154 |
+
<item index="146" class="java.lang.String" itemvalue="gradio" />
|
155 |
+
<item index="147" class="java.lang.String" itemvalue="huggingface-hub" />
|
156 |
+
<item index="148" class="java.lang.String" itemvalue="PyYAML" />
|
157 |
+
<item index="149" class="java.lang.String" itemvalue="MarkupSafe" />
|
158 |
+
<item index="150" class="java.lang.String" itemvalue="requests" />
|
159 |
+
<item index="151" class="java.lang.String" itemvalue="Jinja2" />
|
160 |
+
<item index="152" class="java.lang.String" itemvalue="markdown-it-py" />
|
161 |
+
<item index="153" class="java.lang.String" itemvalue="fsspec" />
|
162 |
+
<item index="154" class="java.lang.String" itemvalue="jsonschema-specifications" />
|
163 |
+
<item index="155" class="java.lang.String" itemvalue="semantic-version" />
|
164 |
+
<item index="156" class="java.lang.String" itemvalue="tomlkit" />
|
165 |
+
<item index="157" class="java.lang.String" itemvalue="filelock" />
|
166 |
+
<item index="158" class="java.lang.String" itemvalue="gradio_client" />
|
167 |
+
<item index="159" class="java.lang.String" itemvalue="Pygments" />
|
168 |
+
<item index="160" class="java.lang.String" itemvalue="safetensors" />
|
169 |
+
<item index="161" class="java.lang.String" itemvalue="starlette" />
|
170 |
+
<item index="162" class="java.lang.String" itemvalue="mdurl" />
|
171 |
+
<item index="163" class="java.lang.String" itemvalue="jsonschema" />
|
172 |
+
<item index="164" class="java.lang.String" itemvalue="tokenizers" />
|
173 |
+
<item index="165" class="java.lang.String" itemvalue="transformers" />
|
174 |
+
<item index="166" class="java.lang.String" itemvalue="importlib_resources" />
|
175 |
+
<item index="167" class="java.lang.String" itemvalue="aiofiles" />
|
176 |
+
<item index="168" class="java.lang.String" itemvalue="rich" />
|
177 |
+
<item index="169" class="java.lang.String" itemvalue="pydub" />
|
178 |
+
<item index="170" class="java.lang.String" itemvalue="python-multipart" />
|
179 |
+
<item index="171" class="java.lang.String" itemvalue="click" />
|
180 |
+
<item index="172" class="java.lang.String" itemvalue="altair" />
|
181 |
+
<item index="173" class="java.lang.String" itemvalue="attrs" />
|
182 |
+
<item index="174" class="java.lang.String" itemvalue="fastapi" />
|
183 |
+
<item index="175" class="java.lang.String" itemvalue="regex" />
|
184 |
+
<item index="176" class="java.lang.String" itemvalue="toolz" />
|
185 |
+
<item index="177" class="java.lang.String" itemvalue="ruff" />
|
186 |
+
<item index="178" class="java.lang.String" itemvalue="charset-normalizer" />
|
187 |
+
<item index="179" class="java.lang.String" itemvalue="ffmpy" />
|
188 |
+
<item index="180" class="java.lang.String" itemvalue="shellingham" />
|
189 |
+
<item index="181" class="java.lang.String" itemvalue="langchain" />
|
190 |
+
<item index="182" class="java.lang.String" itemvalue="sentence-transformers" />
|
191 |
+
<item index="183" class="java.lang.String" itemvalue="Pillow" />
|
192 |
+
<item index="184" class="java.lang.String" itemvalue="langchain-text-splitters" />
|
193 |
+
<item index="185" class="java.lang.String" itemvalue="langchain_core" />
|
194 |
+
<item index="186" class="java.lang.String" itemvalue="langchain_community" />
|
195 |
+
</list>
|
196 |
+
</value>
|
197 |
+
</option>
|
198 |
+
</inspection_tool>
|
199 |
+
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
200 |
+
<option name="ignoredIdentifiers">
|
201 |
+
<list>
|
202 |
+
<option value="spaces" />
|
203 |
+
</list>
|
204 |
+
</option>
|
205 |
+
</inspection_tool>
|
206 |
+
</profile>
|
207 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="Black">
|
4 |
+
<option name="sdkName" value="Python 3.12" />
|
5 |
+
</component>
|
6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
7 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/AskMoondream.iml" filepath="$PROJECT_DIR$/.idea/AskMoondream.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import torch
|
3 |
+
import re
|
4 |
+
import gradio as gr
|
5 |
+
from threading import Thread
|
6 |
+
from transformers import TextIteratorStreamer, AutoTokenizer, AutoModelForCausalLM
|
7 |
+
|
8 |
+
import subprocess
|
9 |
+
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
10 |
+
|
11 |
+
model_id = "vikhyatk/moondream2"
|
12 |
+
revision = "2024-04-02"
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
14 |
+
moondream = AutoModelForCausalLM.from_pretrained(
|
15 |
+
model_id, trust_remote_code=True, revision=revision,
|
16 |
+
torch_dtype=torch.bfloat16, device_map={"": "cuda"},
|
17 |
+
attn_implementation="flash_attention_2"
|
18 |
+
)
|
19 |
+
moondream.eval()
|
20 |
+
|
21 |
+
|
22 |
+
@spaces.GPU(duration=10)
|
23 |
+
def answer_question(img, prompt):
|
24 |
+
image_embeds = moondream.encode_image(img)
|
25 |
+
streamer = TextIteratorStreamer(tokenizer, skip_special_tokens=True)
|
26 |
+
thread = Thread(
|
27 |
+
target=moondream.answer_question,
|
28 |
+
kwargs={
|
29 |
+
"image_embeds": image_embeds,
|
30 |
+
"question": prompt,
|
31 |
+
"tokenizer": tokenizer,
|
32 |
+
"streamer": streamer,
|
33 |
+
},
|
34 |
+
)
|
35 |
+
thread.start()
|
36 |
+
|
37 |
+
buffer = ""
|
38 |
+
for new_text in streamer:
|
39 |
+
buffer += new_text
|
40 |
+
yield buffer.strip()
|
41 |
+
|
42 |
+
|
43 |
+
with gr.Blocks() as demo:
|
44 |
+
gr.Markdown(
|
45 |
+
"""
|
46 |
+
# π moondream2
|
47 |
+
A tiny vision language model. [GitHub](https://github.com/vikhyat/moondream)
|
48 |
+
"""
|
49 |
+
)
|
50 |
+
with gr.Row():
|
51 |
+
prompt = gr.Textbox(label="Input", value="Describe this image.", scale=4)
|
52 |
+
submit = gr.Button("Submit")
|
53 |
+
with gr.Row():
|
54 |
+
img = gr.Image(type="pil", label="Upload an Image")
|
55 |
+
output = gr.TextArea(label="Response")
|
56 |
+
submit.click(answer_question, [img, prompt], output)
|
57 |
+
prompt.submit(answer_question, [img, prompt], output)
|
58 |
+
|
59 |
+
demo.queue().launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
timm==0.9.12
|
2 |
+
transformers==4.36.2
|
3 |
+
einops==0.7.0
|
4 |
+
accelerate==0.25.0
|