Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- app.py +52 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
def process_image(input_image, size_option):
|
| 7 |
+
"""
|
| 8 |
+
This is a placeholder function that demonstrates image processing.
|
| 9 |
+
In a real application, you would implement proper image editing here.
|
| 10 |
+
"""
|
| 11 |
+
# Convert to numpy array
|
| 12 |
+
img = np.array(input_image)
|
| 13 |
+
|
| 14 |
+
# Convert to grayscale for demonstration
|
| 15 |
+
processed_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 16 |
+
|
| 17 |
+
# Add a watermark to show this is just a demo
|
| 18 |
+
cv2.putText(processed_img, "DEMO ONLY", (50, 50),
|
| 19 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
|
| 20 |
+
|
| 21 |
+
# Add text based on size option
|
| 22 |
+
size_text = f"Size: {size_option}"
|
| 23 |
+
cv2.putText(processed_img, size_text, (50, 100),
|
| 24 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
|
| 25 |
+
|
| 26 |
+
return Image.fromarray(processed_img)
|
| 27 |
+
|
| 28 |
+
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("# Image Processing Demo")
|
| 30 |
+
gr.Markdown("Built with [anycoder](https://huggingface.co/spaces/akhaliq/anycoder)")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
input_image = gr.Image(label="Upload Image", type="pil")
|
| 35 |
+
size_option = gr.Radio(["Small", "Medium", "Large"],
|
| 36 |
+
label="Processing Option",
|
| 37 |
+
value="Medium")
|
| 38 |
+
submit_btn = gr.Button("Process Image")
|
| 39 |
+
|
| 40 |
+
with gr.Column():
|
| 41 |
+
output_image = gr.Image(label="Processed Result")
|
| 42 |
+
|
| 43 |
+
submit_btn.click(
|
| 44 |
+
fn=process_image,
|
| 45 |
+
inputs=[input_image, size_option],
|
| 46 |
+
outputs=output_image
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
demo.launch(
|
| 50 |
+
theme=gr.themes.Soft(primary_hue="blue"),
|
| 51 |
+
footer_links=[{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}]
|
| 52 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Pillow
|
| 2 |
+
cv2
|
| 3 |
+
gradio
|
| 4 |
+
numpy
|