Nojoodalnahdi commited on
Commit
1652e69
1 Parent(s): dc7375b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -43
app.py CHANGED
@@ -1,47 +1,7 @@
1
  import gradio as gr
2
- from PIL import Image, ImageDraw, ImageFont
3
 
4
  def greet(name):
5
- try:
6
- # Create an image with a blue background
7
- img = Image.new('RGB', (500, 300), color=(100, 150, 255))
8
-
9
- # Initialize the drawing context with the image object
10
- draw = ImageDraw.Draw(img)
11
-
12
- # Path to the custom font file
13
- font_path = "fonts/arial.ttf" # Adjust the path as needed
14
-
15
- try:
16
- # Try to use the custom font
17
- font = ImageFont.truetype(font_path, 40)
18
- except IOError:
19
- # Fallback to default font if the custom font is not found
20
- print("Custom font not found, using default font.")
21
- font = ImageFont.load_default()
22
-
23
- # Define the text to be added to the image
24
- text = f"Hello {name}!!"
25
-
26
- # Calculate the size of the text to center it
27
- text_width, text_height = draw.textsize(text, font=font)
28
-
29
- # Calculate the x, y position of the text to be centered
30
- x = (img.width - text_width) // 2
31
- y = (img.height - text_height) // 2
32
-
33
- # Draw the text on the image
34
- draw.text((x, y), text, fill=(255, 255, 255), font=font) # White text color
35
-
36
- return img
37
-
38
- except Exception as e:
39
- # Print the error message for debugging
40
- print(f"Error generating image: {e}")
41
- return None # Return None if there's an error to avoid breaking the app
42
 
43
- # Set up the Gradio interface
44
- demo = gr.Interface(fn=greet, inputs="text", outputs="image")
45
-
46
- # Launch the app
47
- demo.launch()
 
1
  import gradio as gr
 
2
 
3
  def greet(name):
4
+ return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ demo.launch()