kadirnar commited on
Commit
b38913b
1 Parent(s): 627f809

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -1
app.py CHANGED
@@ -1 +1,46 @@
1
- # test
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import tempfile
4
+ import shutil
5
+
6
+ def run_inference(config_path, ckpt_path, prompt_path):
7
+ with open(config_path, 'r') as file:
8
+ config_content = file.read()
9
+ config_content = config_content.replace('prompt_path = "./assets/texts/t2v_samples.txt"', f'prompt_path = "{prompt_path}"')
10
+
11
+ with tempfile.NamedTemporaryFile('w', delete=False) as temp_file:
12
+ temp_file.write(config_content)
13
+ temp_config_path = temp_file.name
14
+
15
+ cmd = [
16
+ "torchrun", "--standalone", "--nproc_per_node", "1",
17
+ "scripts/inference.py", temp_config_path,
18
+ "--ckpt-path", ckpt_path
19
+ ]
20
+ result = subprocess.run(cmd, capture_output=True, text=True)
21
+
22
+ shutil.rmtree(temp_config_path)
23
+
24
+ if result.returncode == 0:
25
+ return "Inference completed successfully.", result.stdout
26
+ else:
27
+ return "Error occurred:", result.stderr
28
+
29
+ def main():
30
+ gr.Interface(
31
+ fn=run_inference,
32
+ inputs=[
33
+ gr.Textbox(label="Configuration Path"),
34
+ gr.Dropdown(choices=["./path/to/model1.ckpt", "./path/to/model2.ckpt", "./path/to/model3.ckpt"], label="Checkpoint Path"),
35
+ gr.Textbox(label="Prompt Path")
36
+ ],
37
+ outputs=[
38
+ gr.Text(label="Status"),
39
+ gr.Text(label="Output")
40
+ ],
41
+ title="Open-Sora Inference",
42
+ description="Run Open-Sora Inference with Custom Parameters"
43
+ ).launch()
44
+
45
+ if __name__ == "__main__":
46
+ main()