ayajoharji commited on
Commit
9685466
·
verified ·
1 Parent(s): 7d14001

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -74
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  # Import Libraries
2
  import numpy as np
3
  import gradio as gr
@@ -34,76 +36,20 @@ translation_pipeline = pipeline(
34
 
35
  print("Pipelines loaded successfully.")
36
 
37
- # Function to Download Example Images
38
- def download_example_images():
39
- """
40
- Downloads example images from provided URLs and saves them locally.
41
-
42
- Returns:
43
- examples (list): A list of file paths to the downloaded example images.
44
- """
45
- # List of image descriptions and URLs
46
- image_urls = [
47
- # URL format: ("Image Description", "Image URL")
48
- (
49
- "Sunset over Mountains",
50
- "https://images.unsplash.com/photo-1501785888041-af3ef285b470?w=512"
51
- ),
52
- (
53
- "Forest Path",
54
- "https://images.unsplash.com/photo-1502082553048-f009c37129b9?w=512"
55
- ),
56
- (
57
- "City Skyline",
58
- "https://images.unsplash.com/photo-1498598453737-8913e843c47b?w=512"
59
- ),
60
- (
61
- "Beach and Ocean",
62
- "https://images.unsplash.com/photo-1507525428034-b723cf961d3e?w=512"
63
- ),
64
- (
65
- "Desert Dunes",
66
- "https://images.unsplash.com/photo-1501594907352-04cda38ebc29?w=512"
67
- ),
68
- (
69
- "Snowy Mountain Peak",
70
- "https://images.unsplash.com/photo-1519608487953-e999c86e7455?w=512"
71
- ),
72
- (
73
- "Autumn Leaves",
74
- "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=512"
75
- ),
76
- (
77
- "City Street at Night",
78
- "https://images.unsplash.com/photo-1512453979798-5ea266f8880c?w=512"
79
- ),
80
- (
81
- "Calm Lake Reflection",
82
- "https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=512"
83
- ),
84
- (
85
- "Lush Green Hills",
86
- "https://images.unsplash.com/photo-1501696461280-37c52f57e8c1?w=512"
87
- ),
88
- ]
89
-
90
- examples = []
91
- for idx, (description, url) in enumerate(image_urls, start=1):
92
- try:
93
- response = requests.get(url)
94
- if response.status_code == 200:
95
- # Open the image and save it locally
96
- img = Image.open(BytesIO(response.content))
97
- img.save(f'example{idx}.jpg')
98
- examples.append([f'example{idx}.jpg'])
99
- else:
100
- print(f"Failed to download image from {url}")
101
- except Exception as e:
102
- print(f"Exception occurred while downloading image: {e}")
103
- return examples
104
-
105
- # Download example images and prepare examples list
106
- examples = download_example_images()
107
 
108
  # Function to Load and Process Image
109
  def load_image(image):
@@ -333,12 +279,13 @@ with gr.Blocks(
333
  )
334
  # Submit Button
335
  submit_button = gr.Button("Submit")
336
- # Examples Component
337
  gr.Examples(
338
- examples=examples,
339
  inputs=image_input,
340
  label="Example Images",
341
- examples_per_page=5,
 
342
  )
343
  with gr.Column(scale=1):
344
  # Output Components
@@ -373,4 +320,4 @@ with gr.Blocks(
373
  )
374
 
375
  # Launch Gradio Interface
376
- demo.launch()
 
1
+ # app.py
2
+
3
  # Import Libraries
4
  import numpy as np
5
  import gradio as gr
 
36
 
37
  print("Pipelines loaded successfully.")
38
 
39
+ # Define a list of image URLs for examples
40
+ image_examples = [
41
+ ["https://images.unsplash.com/photo-1501785888041-af3ef285b470?w=512"],
42
+ ["https://images.unsplash.com/photo-1502082553048-f009c37129b9?w=512"],
43
+ ["https://images.unsplash.com/photo-1498598453737-8913e843c47b?w=512"],
44
+ ["https://images.unsplash.com/photo-1507525428034-b723cf961d3e?w=512"],
45
+ ["https://images.unsplash.com/photo-1501594907352-04cda38ebc29?w=512"],
46
+ ["https://images.unsplash.com/photo-1519608487953-e999c86e7455?w=512"],
47
+ ["https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=512"],
48
+ ["https://images.unsplash.com/photo-1512453979798-5ea266f8880c?w=512"],
49
+ ["https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=512"],
50
+ ["https://images.unsplash.com/photo-1501696461280-37c52f57e8c1?w=512"],
51
+ # Add more image URLs as needed
52
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  # Function to Load and Process Image
55
  def load_image(image):
 
279
  )
280
  # Submit Button
281
  submit_button = gr.Button("Submit")
282
+ # Examples Component using Image URLs directly
283
  gr.Examples(
284
+ examples=image_examples, # List of lists with image URLs
285
  inputs=image_input,
286
  label="Example Images",
287
+ examples_per_page=10, # Adjust as needed
288
+ fn=None, # No need to specify a function since we're using URLs
289
  )
290
  with gr.Column(scale=1):
291
  # Output Components
 
320
  )
321
 
322
  # Launch Gradio Interface
323
+ demo.launch()