Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from aura_sr import AuraSR
|
2 |
import gradio as gr
|
3 |
import spaces
|
|
|
1 |
+
'''
|
2 |
+
import os
|
3 |
+
from gradio_client import Client, handle_file
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Initialize Gradio client
|
7 |
+
client = Client("http://localhost:7860")
|
8 |
+
|
9 |
+
# Path configuration
|
10 |
+
input_dir = "Aesthetics_X_Phone_720p_Images_Rec_Captioned_16_9"
|
11 |
+
output_dir = "processed_output_v2_single_thread"
|
12 |
+
os.makedirs(output_dir, exist_ok=True)
|
13 |
+
|
14 |
+
def process_single_image(png_path):
|
15 |
+
"""Process a single image and save results"""
|
16 |
+
try:
|
17 |
+
# Get base filename without extension
|
18 |
+
base_name = os.path.splitext(os.path.basename(png_path))[0]
|
19 |
+
|
20 |
+
# Corresponding text file path
|
21 |
+
txt_path = os.path.join(input_dir, f"{base_name}.txt")
|
22 |
+
|
23 |
+
print(f"Processing: {png_path}...", end=" ", flush=True)
|
24 |
+
|
25 |
+
# Process image through API (returns WEBP path)
|
26 |
+
webp_result = client.predict(
|
27 |
+
img=handle_file(png_path),
|
28 |
+
model_selection="v2",
|
29 |
+
api_name="/predict"
|
30 |
+
)
|
31 |
+
|
32 |
+
# Output paths
|
33 |
+
output_image_path = os.path.join(output_dir, f"{base_name}.png")
|
34 |
+
output_text_path = os.path.join(output_dir, f"{base_name}.txt")
|
35 |
+
|
36 |
+
# Convert WEBP to PNG
|
37 |
+
with Image.open(webp_result) as img:
|
38 |
+
img.save(output_image_path, "PNG")
|
39 |
+
|
40 |
+
# Copy corresponding text file if exists
|
41 |
+
if os.path.exists(txt_path):
|
42 |
+
with open(txt_path, 'r', encoding='utf-8') as src, \
|
43 |
+
open(output_text_path, 'w', encoding='utf-8') as dst:
|
44 |
+
dst.write(src.read())
|
45 |
+
|
46 |
+
print("Done")
|
47 |
+
return True
|
48 |
+
|
49 |
+
except Exception as e:
|
50 |
+
print(f"Failed: {str(e)}")
|
51 |
+
return False
|
52 |
+
|
53 |
+
def main():
|
54 |
+
# Get all PNG files in input directory
|
55 |
+
png_files = sorted([
|
56 |
+
os.path.join(input_dir, f)
|
57 |
+
for f in os.listdir(input_dir)
|
58 |
+
if f.lower().endswith('.png')
|
59 |
+
])
|
60 |
+
|
61 |
+
print(f"Found {len(png_files)} PNG files to process")
|
62 |
+
|
63 |
+
# Process files one by one
|
64 |
+
success_count = 0
|
65 |
+
for i, png_path in enumerate(png_files, 1):
|
66 |
+
print(f"\n[{i}/{len(png_files)}] ", end="")
|
67 |
+
if process_single_image(png_path):
|
68 |
+
success_count += 1
|
69 |
+
|
70 |
+
print(f"\nProcessing complete! Success: {success_count}/{len(png_files)}")
|
71 |
+
|
72 |
+
if __name__ == "__main__":
|
73 |
+
main()
|
74 |
+
'''
|
75 |
+
|
76 |
from aura_sr import AuraSR
|
77 |
import gradio as gr
|
78 |
import spaces
|