blind1234 commited on
Commit
4341494
·
verified ·
0 Parent(s):

initial commit

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +13 -0
  3. app.py +61 -0
  4. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Create Image
3
+ emoji: ⚡
4
+ colorFrom: red
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 5.6.0
8
+ app_file: app.py
9
+ pinned: false
10
+ short_description: Create images from text Set colors and more
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is a Gradio app to convert text into images with adjustable colors, fonts, and alignment.
2
+ import gradio as gr
3
+ import matplotlib.pyplot as plt
4
+ import numpy as np
5
+
6
+ # Function to convert text to an image
7
+ def text_to_image(text, font_size, font_color, bg_color, text_align, width, height):
8
+ # Create a figure and axis with specified width and height
9
+ fig, ax = plt.subplots(figsize=(width, height))
10
+
11
+ # Set the background color
12
+ ax.set_facecolor(bg_color)
13
+
14
+ # Display the text with specified alignment
15
+ ax.text(0.5, 0.5, text, fontsize=font_size, color=font_color, ha=text_align, va='center')
16
+
17
+ # Remove axes
18
+ ax.axis('off')
19
+
20
+ # Convert the plot to an image
21
+ fig.canvas.draw()
22
+ img = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
23
+ img = img.reshape(fig.canvas.get_width_height()[::-1] + (3,))
24
+
25
+ # Close the plot
26
+ plt.close(fig)
27
+
28
+ return img
29
+
30
+ # Create a Gradio interface
31
+ with gr.Blocks() as demo:
32
+ # Input components
33
+ text_input = gr.Textbox(label="Text", placeholder="Enter your text here")
34
+ font_size_slider = gr.Slider(10, 100, value=20, label="Font Size")
35
+ font_color_picker = gr.ColorPicker(label="Font Color", value="#000000")
36
+ bg_color_picker = gr.ColorPicker(label="Background Color", value="#FFFFFF")
37
+ text_align_dropdown = gr.Dropdown(choices=["left", "center", "right"], value="center", label="Text Alignment")
38
+ width_slider = gr.Slider(1, 10, value=5, label="Width")
39
+ height_slider = gr.Slider(1, 10, value=5, label="Height")
40
+
41
+ # Output component
42
+ image_output = gr.Image(label="Generated Image")
43
+
44
+ # Define the event listener
45
+ create_button = gr.Button("Create")
46
+ create_button.click(
47
+ fn=text_to_image,
48
+ inputs=[text_input, font_size_slider, font_color_picker, bg_color_picker, text_align_dropdown, width_slider, height_slider],
49
+ outputs=image_output
50
+ )
51
+
52
+ # Initial call to generate the image
53
+ create_button.click(
54
+ fn=text_to_image,
55
+ inputs=[text_input, font_size_slider, font_color_picker, bg_color_picker, text_align_dropdown, width_slider, height_slider],
56
+ outputs=image_output
57
+ )
58
+
59
+ # Launch the interface
60
+ if __name__ == "__main__":
61
+ demo.launch(show_error=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ matplotlib
2
+ numpy