akhaliq HF staff commited on
Commit
8be0786
1 Parent(s): c8ce5d3

Create new file

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ os.system("pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html")
4
+ os.system("git clone https://github.com/Sleepychord/Image-Local-Attention")
5
+ os.chdir("Image-Local-Attention")
6
+ os.system("python setup.py install")
7
+ os.chdir("..")
8
+ os.system("git clone https://github.com/NVIDIA/apex")
9
+ os.chdir("apex")
10
+ os.system('pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./')
11
+ os.chdir("..")
12
+ os.system("git clone https://github.com/THUDM/CogView2")
13
+ os.chdir("CogView2")
14
+ os.system("gdown https://drive.google.com/uc?id=1-2nI2TTUOdiQ2WpydGafk_bZIZggQBK4")
15
+ os.system("7za x coglm.zip")
16
+ os.system("gdown https://drive.google.com/uc?id=1ulfXJFstYZUestvWcQIadKkNNDVbpIdM")
17
+ os.mkdir("/root/.icetk_models")
18
+ os.system("cp /home/user/app/CogView2/ice_image.pt /root/.icetk_models/ice_image.pt")
19
+
20
+ def inference(text):
21
+ with open("input.txt") as f:
22
+ lines = f.readlines()
23
+ lines[0] = text
24
+ with open("input.txt", "w") as f:
25
+ f.writelines(lines)
26
+ os.system("python cogview2_text2image.py --mode inference --fp16 --input-source input.txt --output-path samples_sat_v0.2 --batch-size 4 --max-inference-batch-size 8 --only-first-stage")
27
+ return "/content/CogView2/output.png"
28
+
29
+ gr.Interface(inference,"text","image",title="CogView 2").launch(debug=True,enable_queue=True)
30
+
31
+
32
+
33
+
34
+