Spaces:
Sleeping
Sleeping
Update src/pyscripts/run.py
Browse files- src/pyscripts/run.py +31 -1
src/pyscripts/run.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI, Path, Query, Response, BackgroundTasks
|
|
| 2 |
from fastapi.responses import FileResponse, HTMLResponse
|
| 3 |
import gradio as gr
|
| 4 |
import sys
|
|
|
|
| 5 |
import os
|
| 6 |
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
| 7 |
sys.path.append(project_root)
|
|
@@ -164,9 +165,38 @@ def getGuestComposePoster(item:ConferenceInfo):
|
|
| 164 |
return {"url": file_url}
|
| 165 |
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
interface = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
|
| 169 |
-
app = gr.
|
| 170 |
|
| 171 |
|
| 172 |
if __name__ == "__main__":
|
|
|
|
| 2 |
from fastapi.responses import FileResponse, HTMLResponse
|
| 3 |
import gradio as gr
|
| 4 |
import sys
|
| 5 |
+
import re
|
| 6 |
import os
|
| 7 |
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
| 8 |
sys.path.append(project_root)
|
|
|
|
| 165 |
return {"url": file_url}
|
| 166 |
|
| 167 |
|
| 168 |
+
class GuestEScreenInfo(BaseModel):
|
| 169 |
+
room_types: list
|
| 170 |
+
person: object
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
@app.post("/getGuestEScreen")
|
| 175 |
+
def getGuestEScreen(item: GuestEScreenInfo):
|
| 176 |
+
file_dir = "GuestEScreen"
|
| 177 |
+
file_urls = []
|
| 178 |
+
for room_type in item.room_types:
|
| 179 |
+
rt = ""
|
| 180 |
+
if room_type.startswith("M"):
|
| 181 |
+
rt = "M"
|
| 182 |
+
elif re.match(r"^\d+", room_type):
|
| 183 |
+
rt = "half"
|
| 184 |
+
else:
|
| 185 |
+
rt = "full"
|
| 186 |
+
img_stream = img_process.getGuestEScreen(rt, item.person)
|
| 187 |
+
object_name = file_dir + "/" + item.name + ".jpg"
|
| 188 |
+
if os.path.exists("src/assets/output"):
|
| 189 |
+
with open(f"src/assets/output/{item.name + '.jpg'}", 'wb') as f:
|
| 190 |
+
f.write(img_stream.getvalue())
|
| 191 |
+
else:
|
| 192 |
+
oss.upload_file_stream_to_s3(img_stream, "host", object_name)
|
| 193 |
+
file_url = f"https://pub-429c75a96a8f4597984dd7ebc525d652.r2.dev/{object_name}"
|
| 194 |
+
file_urls.append(file_url)
|
| 195 |
+
return {"url": "\n".join(file_urls)}
|
| 196 |
+
|
| 197 |
|
| 198 |
interface = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
|
| 199 |
+
app = gr.getGuestEScreen(app, interface, path=CUSTOM_PATH)
|
| 200 |
|
| 201 |
|
| 202 |
if __name__ == "__main__":
|