Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2053,42 +2053,9 @@ with gr.Blocks(
|
|
| 2053 |
theme=gr.themes.Soft(),
|
| 2054 |
css="""
|
| 2055 |
.gradio-container {
|
| 2056 |
-
max-width: 1200px !important;
|
| 2057 |
-
margin: 0 auto;
|
| 2058 |
-
}
|
| 2059 |
-
.output-text {
|
| 2060 |
-
font-family: monospace;
|
| 2061 |
-
font-size: 14px !important;
|
| 2062 |
-
}
|
| 2063 |
-
.file-upload {
|
| 2064 |
-
border: 2px dashed #ccc !important;
|
| 2065 |
-
border-radius: 10px !important;
|
| 2066 |
-
padding: 20px !important;
|
| 2067 |
-
}
|
| 2068 |
-
.icon {
|
| 2069 |
-
font-size: 16px !important;
|
| 2070 |
-
}
|
| 2071 |
-
.gr-button {
|
| 2072 |
-
font-size: 16px !important;
|
| 2073 |
-
}
|
| 2074 |
-
.gr-markdown h1 {
|
| 2075 |
-
font-size: 2em !important;
|
| 2076 |
-
margin-bottom: 0.5em !important;
|
| 2077 |
-
}
|
| 2078 |
-
.gr-markdown h2 {
|
| 2079 |
-
font-size: 1.5em !important;
|
| 2080 |
-
margin-bottom: 0.5em !important;
|
| 2081 |
-
}
|
| 2082 |
-
.gr-markdown h3 {
|
| 2083 |
-
font-size: 1.2em !important;
|
| 2084 |
-
margin-bottom: 0.5em !important;
|
| 2085 |
-
}
|
| 2086 |
-
.upload-text {
|
| 2087 |
-
font-size: 14px !important;
|
| 2088 |
-
}
|
| 2089 |
-
.container {
|
| 2090 |
max-width: 1200px;
|
| 2091 |
margin: 0 auto;
|
|
|
|
| 2092 |
}
|
| 2093 |
"""
|
| 2094 |
) as demo:
|
|
@@ -2173,27 +2140,38 @@ with gr.Blocks(
|
|
| 2173 |
- `GET /api/health` - Health check
|
| 2174 |
""")
|
| 2175 |
|
| 2176 |
-
app = gr.mount_gradio_app(app, demo, path="/")
|
| 2177 |
|
| 2178 |
# For Hugging Face Spaces, we need to expose the app
|
| 2179 |
if __name__ == "__main__":
|
| 2180 |
-
|
| 2181 |
-
|
| 2182 |
-
app,
|
| 2183 |
-
host="0.0.0.0",
|
| 2184 |
-
port=7860,
|
| 2185 |
-
log_level="info"
|
| 2186 |
-
)
|
| 2187 |
|
| 2188 |
-
#
|
| 2189 |
-
|
| 2190 |
-
# # Mount Gradio to FastAPI
|
| 2191 |
-
# app = gr.mount_gradio_app(app, demo, path="/")
|
| 2192 |
|
| 2193 |
-
|
| 2194 |
-
#
|
| 2195 |
-
|
| 2196 |
-
|
| 2197 |
-
|
| 2198 |
-
|
| 2199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2053 |
theme=gr.themes.Soft(),
|
| 2054 |
css="""
|
| 2055 |
.gradio-container {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2056 |
max-width: 1200px;
|
| 2057 |
margin: 0 auto;
|
| 2058 |
+
padding: 20px;
|
| 2059 |
}
|
| 2060 |
"""
|
| 2061 |
) as demo:
|
|
|
|
| 2140 |
- `GET /api/health` - Health check
|
| 2141 |
""")
|
| 2142 |
|
|
|
|
| 2143 |
|
| 2144 |
# For Hugging Face Spaces, we need to expose the app
|
| 2145 |
if __name__ == "__main__":
|
| 2146 |
+
# For Hugging Face Spaces deployment
|
| 2147 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2148 |
|
| 2149 |
+
# Check if running on Hugging Face Spaces
|
| 2150 |
+
is_hf_space = os.environ.get('SPACE_ID') is not None
|
|
|
|
|
|
|
| 2151 |
|
| 2152 |
+
if is_hf_space:
|
| 2153 |
+
# On HF Spaces: Mount Gradio to FastAPI and launch together
|
| 2154 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 2155 |
+
uvicorn.run(
|
| 2156 |
+
app,
|
| 2157 |
+
host="0.0.0.0",
|
| 2158 |
+
port=7860,
|
| 2159 |
+
log_level="info"
|
| 2160 |
+
)
|
| 2161 |
+
else:
|
| 2162 |
+
# Local development: Launch separately
|
| 2163 |
+
import threading
|
| 2164 |
+
|
| 2165 |
+
# Start FastAPI in background thread
|
| 2166 |
+
def run_fastapi():
|
| 2167 |
+
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="info")
|
| 2168 |
+
|
| 2169 |
+
api_thread = threading.Thread(target=run_fastapi, daemon=True)
|
| 2170 |
+
api_thread.start()
|
| 2171 |
+
|
| 2172 |
+
# Launch Gradio on main thread
|
| 2173 |
+
demo.launch(
|
| 2174 |
+
server_name="0.0.0.0",
|
| 2175 |
+
server_port=7860,
|
| 2176 |
+
share=False
|
| 2177 |
+
)
|