NickKolok commited on
Commit
1106a9f
·
verified ·
1 Parent(s): 4db9c56

Revert to gradio 2.9 (hope it works!!)

Browse files
Files changed (1) hide show
  1. app.py +20 -32
app.py CHANGED
@@ -1,41 +1,34 @@
1
  import os
 
 
 
2
  import random
3
  import gradio as gr
4
  from PIL import Image
5
  import torch
6
  from random import randint
7
  import sys
 
8
  import psutil
9
- import subprocess
10
- import sys
11
 
12
- def run_cmd(command):
13
- try:
14
- print(f"Running command: {command}")
15
- # Run the command and capture both output and error
16
- result = subprocess.run(command, shell=True, text=True, capture_output=True)
17
 
18
- # Print stdout and stderr
19
- if result.stdout:
20
- print("Output:\n", result.stdout)
21
-
22
- if result.stderr:
23
- print("Error:\n", result.stderr)
24
-
25
- # Check for command success
26
- if result.returncode != 0:
27
- print(f"Command failed with return code {result.returncode}")
28
 
 
 
 
 
 
 
 
 
29
  except KeyboardInterrupt:
30
  print("Process interrupted")
31
  sys.exit(1)
32
-
33
-
34
  run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
35
  run_cmd("pip install basicsr")
36
  run_cmd("pip freeze")
37
 
38
- run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
39
 
40
 
41
  def inference(img,mode):
@@ -54,7 +47,7 @@ def inference(img,mode):
54
  if mode == "base":
55
  run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
56
  else:
57
- run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
58
  return os.path.join(OUTPUT_DIR, "1_out.png")
59
 
60
 
@@ -64,19 +57,14 @@ title = "Real-ESRGAN"
64
  description = "Gradio demo for Real-ESRGAN. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Please click submit only once"
65
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/xinntao/Real-ESRGAN'>Github Repo</a></p>"
66
 
67
- # Updated Gradio Interface
68
  gr.Interface(
69
- fn=inference,
70
- inputs=[
71
- gr.Image(type="pil", label="Input"),
72
- gr.Radio(choices=["base", "anime"], label="Model Type", value="base")
73
- ],
74
- outputs=gr.Image(type="filepath", label="Output"),
75
  title=title,
76
  description=description,
77
  article=article,
78
  examples=[
79
- # ['bear.jpg', 'base'],
80
- # ['anime.png', 'anime']
81
- ]
82
- ).launch()
 
1
  import os
2
+ os.system("pip install gradio==2.9b23")
3
+ #https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13985
4
+ #os.system("python -m pip install torch==2.0.1 torchvision==0.15.2")
5
  import random
6
  import gradio as gr
7
  from PIL import Image
8
  import torch
9
  from random import randint
10
  import sys
11
+ from subprocess import call
12
  import psutil
 
 
13
 
 
 
 
 
 
14
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+
17
+ torch.hub.download_url_to_file('http://people.csail.mit.edu/billf/project%20pages/sresCode/Markov%20Random%20Fields%20for%20Super-Resolution_files/100075_lowres.jpg', 'bear.jpg')
18
+
19
+
20
+ def run_cmd(command):
21
+ try:
22
+ print(command)
23
+ call(command, shell=True)
24
  except KeyboardInterrupt:
25
  print("Process interrupted")
26
  sys.exit(1)
 
 
27
  run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
28
  run_cmd("pip install basicsr")
29
  run_cmd("pip freeze")
30
 
31
+ os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
32
 
33
 
34
  def inference(img,mode):
 
47
  if mode == "base":
48
  run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
49
  else:
50
+ os.system("python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
51
  return os.path.join(OUTPUT_DIR, "1_out.png")
52
 
53
 
 
57
  description = "Gradio demo for Real-ESRGAN. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Please click submit only once"
58
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/xinntao/Real-ESRGAN'>Github Repo</a></p>"
59
 
 
60
  gr.Interface(
61
+ inference,
62
+ [gr.inputs.Image(type="pil", label="Input"),gr.inputs.Radio(["base","anime"], type="value", default="base", label="model type")],
63
+ gr.outputs.Image(type="file", label="Output"),
 
 
 
64
  title=title,
65
  description=description,
66
  article=article,
67
  examples=[
68
+ #['bear.jpg','base'],
69
+ #['anime.png','anime']
70
+ ]).launch()