udayjawheri commited on
Commit
d09f4a0
·
verified ·
1 Parent(s): 70c79b0

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Random Word Genrator
3
- emoji: 📊
4
- colorFrom: purple
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 4.22.0
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Random_Word_Genrator
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 4.19.1
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import cv2
4
+ import gradio as gr
5
+ from PIL import Image
6
+ import numpy as np
7
+
8
+ def generate_and_delete_word_image(word):
9
+ """Generates a combined image, displays it, and deletes it afterward.
10
+
11
+ Args:
12
+ word: The user-provided word (uppercase).
13
+
14
+ Returns:
15
+ The image data for displaying.
16
+ """
17
+
18
+ dataset_path = "C:\DYPIU\___________________CODE___________________\Random Word Genrator\dataset" # Adjust for your dataset path
19
+ sample = "C:\DYPIU\___________________CODE___________________\Random Word Genrator\dataset\samples.jpg"
20
+ resized_images = []
21
+ for letter in word:
22
+ letter_folder_path = os.path.join(dataset_path, letter)
23
+
24
+ # Check if the folder exists
25
+ if not os.path.isdir(letter_folder_path):
26
+ print("Folder not found for the letter:", letter)
27
+ continue
28
+
29
+ images_in_folder = [img for img in os.listdir(letter_folder_path)
30
+ if img.endswith(".jpg") or img.endswith(".png")]
31
+
32
+ if not images_in_folder:
33
+ print("No images found for the letter:", letter)
34
+ continue
35
+
36
+ # Randomly select an image from the folder
37
+ random_image_name = random.choice(images_in_folder)
38
+ image_path = os.path.join(letter_folder_path, random_image_name)
39
+
40
+ try:
41
+ # Load image using PIL, ensuring RGB mode
42
+ image = Image.open(image_path).convert("RGB")
43
+ # Convert to NumPy array for OpenCV
44
+ resized_image = np.array(image.resize((250, 250)))
45
+ except Exception as e:
46
+ print(f"Error loading image: {e}")
47
+ continue
48
+
49
+ resized_images.append(resized_image)
50
+
51
+ if not resized_images:
52
+ print("No images found for the input word.")
53
+ return None
54
+
55
+ sample_img = sample
56
+ concatenated_image = cv2.hconcat(resized_images)
57
+
58
+ # Display the concatenated image
59
+ # cv2.imshow("Concatenated Image", concatenated_image)
60
+ # cv2.waitKey(0)
61
+ # cv2.destroyAllWindows()
62
+
63
+ # Return the image data
64
+ return concatenated_image
65
+
66
+ # Gradio interface with clear explanations
67
+ interface = gr.Interface(
68
+ fn=generate_and_delete_word_image,
69
+ inputs="text", # User input for the word
70
+ outputs="image", # Output as an image
71
+ title="POCKET RANDOM NOTE GENERATOR", # Title
72
+ description="Randsomator allows you to generate random ranson with one click.",
73
+
74
+ css="""
75
+ botton {
76
+ background: green;
77
+ color: #32B531
78
+ }
79
+ body {
80
+ background-color: black;
81
+ font-family: Arial, sans-serif;
82
+ }
83
+ .gr-interactive-component h1 {
84
+ font-size: 20px;
85
+ margin-bottom: 10px;
86
+ }
87
+ """,
88
+
89
+ )
90
+
91
+
92
+ interface.launch(share=True) # Launch the Gradio interface and share it publicly
dataset/0/0.png ADDED
dataset/0/02.png ADDED
dataset/1/1.png ADDED
dataset/1/12.png ADDED
dataset/2/21.png ADDED
dataset/2/22.png ADDED
dataset/2/23.png ADDED
dataset/2/24.png ADDED
dataset/3/3.png ADDED
dataset/3/32.png ADDED
dataset/3/33.png ADDED
dataset/4/4.png ADDED
dataset/4/42.png ADDED
dataset/4/43.png ADDED
dataset/5/5.png ADDED
dataset/5/52.png ADDED
dataset/5/53.png ADDED
dataset/6/6.png ADDED
dataset/6/62.png ADDED
dataset/6/63.png ADDED
dataset/6/64.png ADDED
dataset/7/7.png ADDED
dataset/7/71.png ADDED
dataset/7/72.png ADDED
dataset/7/74.png ADDED
dataset/8/8.png ADDED
dataset/8/82.png ADDED
dataset/8/83.png ADDED
dataset/9/91.png ADDED
dataset/9/92.png ADDED
dataset/9/94.png ADDED
dataset/A/A (1).png ADDED
dataset/A/A2.png ADDED
dataset/A/A3.png ADDED
dataset/A/a.png ADDED
dataset/B/B.png ADDED
dataset/B/B2.png ADDED
dataset/B/B3.png ADDED
dataset/C/C.png ADDED
dataset/C/C2.png ADDED
dataset/C/C3.png ADDED
dataset/D/D.png ADDED
dataset/D/D2.png ADDED
dataset/D/D3.png ADDED
dataset/D/D4.png ADDED
dataset/E/E (1).png ADDED
dataset/E/E2.png ADDED
dataset/E/e.png ADDED