DemahAlmutairi commited on
Commit
9b75e51
·
verified ·
1 Parent(s): 8cb6990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -3
app.py CHANGED
@@ -6,6 +6,9 @@ import spaces
6
  import gc
7
  import torch
8
 
 
 
 
9
  # Create the necessary directories
10
  os.makedirs('.gradio/cached_examples/17', exist_ok=True)
11
 
@@ -42,6 +45,7 @@ def load_model(model_name):
42
 
43
  return generator
44
 
 
45
  @spaces.GPU
46
  def generate_kids_story(character, setting, language):
47
  model_name = get_model_name(language)
@@ -57,15 +61,40 @@ def generate_kids_story(character, setting, language):
57
 
58
  messages = [{"role": "user", "content": prompt}]
59
  output = generator(messages)
60
-
 
 
61
  # Delete model and associated objects
62
  del generator
63
  # Run garbage collection
64
  gc.collect ()
65
  # Empty CUDA cache
66
  torch.cuda.empty_cache()
 
 
 
 
 
 
67
 
68
- return output[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  # Create Gradio interface
71
  demo = gr.Interface(
@@ -88,7 +117,7 @@ demo = gr.Interface(
88
  ["Lila the Ladybug", "a garden full of flowers", "English"],
89
  ["ليلى الجنية", "حديقة مليئة بالأزهار", "Arabic"]
90
  ],
91
- theme="default",
92
  )
93
 
94
  # Launch the Gradio app
 
6
  import gc
7
  import torch
8
 
9
+ from gradio_client import Client
10
+ import pyarabic.araby as araby
11
+
12
  # Create the necessary directories
13
  os.makedirs('.gradio/cached_examples/17', exist_ok=True)
14
 
 
45
 
46
  return generator
47
 
48
+ client = Client("MohamedRashad/arabic-auto-tashkeel")
49
  @spaces.GPU
50
  def generate_kids_story(character, setting, language):
51
  model_name = get_model_name(language)
 
61
 
62
  messages = [{"role": "user", "content": prompt}]
63
  output = generator(messages)
64
+
65
+ text = output[0]["generated_text"]
66
+
67
  # Delete model and associated objects
68
  del generator
69
  # Run garbage collection
70
  gc.collect ()
71
  # Empty CUDA cache
72
  torch.cuda.empty_cache()
73
+
74
+ # Remove diacritics from Arabic text then add tashkeel
75
+ if language == "Arabic":
76
+ text = client.predict(
77
+ input_text=araby.strip_diacritics(text),
78
+ api_name="/infer_shakkala")
79
 
80
+ return text
81
+
82
+ css_style = """
83
+ body {
84
+ background-image: url('https://cdna.artstation.com/p/assets/images/images/074/776/904/large/pietro-chiovaro-r1-castle-chp.jpg?1712916847');
85
+ background-size: cover;
86
+ background-position: center;
87
+ color: #fff; /* General text color */
88
+ font-family: 'Arial', sans-serif;
89
+ }
90
+ .title {
91
+ text-align: center;
92
+ font-size: 3.5em;
93
+ margin: 20px 0;
94
+ text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
95
+ color: #FFD700; /* Gold color for title */
96
+ }
97
+ """
98
 
99
  # Create Gradio interface
100
  demo = gr.Interface(
 
117
  ["Lila the Ladybug", "a garden full of flowers", "English"],
118
  ["ليلى الجنية", "حديقة مليئة بالأزهار", "Arabic"]
119
  ],
120
+ css = css_style
121
  )
122
 
123
  # Launch the Gradio app