From 42f92854f5fe5173ec80af0311778783078e9553 Mon Sep 17 00:00:00 2001
From: memoryunreal <814514103@qq.com>
Date: Sun, 16 Apr 2023 05:37:05 +0000
Subject: [PATCH] flask is kind of web application tool, stronger than gradio,
but need to write html and javascript -- li
---
app_test.py | 23 ++++++++++++++
template.html | 27 +++++++++++++++++
templates/index.html | 50 ++++++++++++++++++++++++++++++
text_server.py | 72 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 172 insertions(+)
create mode 100644 app_test.py
create mode 100644 template.html
create mode 100644 templates/index.html
create mode 100644 text_server.py
diff --git a/app_test.py b/app_test.py
new file mode 100644
index 0000000..80af21c
--- /dev/null
+++ b/app_test.py
@@ -0,0 +1,23 @@
+import gradio as gr
+
+def update_iframe(slider_value):
+ return f'''
+
+
+ '''
+
+iface = gr.Interface(
+ fn=update_iframe,
+ inputs=gr.inputs.Slider(minimum=0, maximum=100, step=1, default=50),
+ outputs=gr.outputs.HTML(),
+ allow_flagging=False,
+)
+
+iface.launch(server_name='0.0.0.0', server_port=12212)
diff --git a/template.html b/template.html
new file mode 100644
index 0000000..c476716
--- /dev/null
+++ b/template.html
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ Gradio Video Pause Time
+
+
+
+
+
+
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..3348583
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+ Video Object Segmentation
+
+
+
+ Video Object Segmentation
+
+
+
+
+
+
+
+
+
+
+ Download Video
+
+
+
+
+
diff --git a/text_server.py b/text_server.py
new file mode 100644
index 0000000..a0623a3
--- /dev/null
+++ b/text_server.py
@@ -0,0 +1,72 @@
+import os
+import sys
+import cv2
+import time
+import json
+import queue
+import numpy as np
+import requests
+import concurrent.futures
+from PIL import Image
+from flask import Flask, render_template, request, jsonify, send_file
+import torchvision
+import torch
+
+from demo import automask_image_app, automask_video_app, sahi_autoseg_app
+sys.path.append(sys.path[0] + "/tracker")
+sys.path.append(sys.path[0] + "/tracker/model")
+from track_anything import TrackingAnything
+from track_anything import parse_augment
+
+# ... (all the functions defined in the original code except the Gradio part)
+
+app = Flask(__name__)
+app.config['UPLOAD_FOLDER'] = './uploaded_videos'
+app.config['ALLOWED_EXTENSIONS'] = {'mp4', 'avi', 'mov', 'mkv'}
+
+
+def allowed_file(filename):
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in app.config['ALLOWED_EXTENSIONS']
+
+@app.route("/")
+def index():
+ return render_template("index.html")
+
+@app.route("/upload_video", methods=["POST"])
+def upload_video():
+ # ... (handle video upload and processing)
+ return jsonify(status="success", data=video_data)
+
+@app.route("/template_select", methods=["POST"])
+def template_select():
+ # ... (handle template selection and processing)
+ return jsonify(status="success", data=template_data)
+
+@app.route("/sam_refine", methods=["POST"])
+def sam_refine_request():
+ # ... (handle sam refine and processing)
+ return jsonify(status="success", data=sam_data)
+
+@app.route("/track_video", methods=["POST"])
+def track_video():
+ # ... (handle video tracking and processing)
+ return jsonify(status="success", data=tracking_data)
+
+@app.route("/track_image", methods=["POST"])
+def track_image():
+ # ... (handle image tracking and processing)
+ return jsonify(status="success", data=tracking_data)
+
+@app.route("/download_video", methods=["GET"])
+def download_video():
+ try:
+ return send_file("output.mp4", attachment_filename="output.mp4")
+ except Exception as e:
+ return str(e)
+
+if __name__ == "__main__":
+ app.run(debug=True, host="0.0.0.0", port=args.port)
+
+
+if __name__ == '__main__':
+ app.run(host="0.0.0.0",port=12212, debug=True)