Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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,7 +45,7 @@ def load_model(model_name):
|
|
| 42 |
|
| 43 |
return generator
|
| 44 |
|
| 45 |
-
|
| 46 |
@spaces.GPU
|
| 47 |
def generate_kids_story(character, setting, language):
|
| 48 |
model_name = get_model_name(language)
|
|
@@ -58,14 +61,34 @@ def generate_kids_story(character, setting, language):
|
|
| 58 |
|
| 59 |
messages = [{"role": "user", "content": prompt}]
|
| 60 |
output = generator(messages)
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# Create Gradio interface
|
| 71 |
demo = gr.Interface(
|
|
@@ -87,8 +110,8 @@ demo = gr.Interface(
|
|
| 87 |
["علي البطل", "غابة سحرية", "Arabic"],
|
| 88 |
["Lila the Ladybug", "a garden full of flowers", "English"],
|
| 89 |
["ليلى الجنية", "حديقة مليئة بالأزهار", "Arabic"]
|
| 90 |
-
],
|
| 91 |
-
|
| 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 |
+
|
| 75 |
+
# Remove diacritics from Arabic text then add tashkeel
|
| 76 |
+
if language == "Arabic":
|
| 77 |
+
text = client.predict(
|
| 78 |
+
input_text=araby.strip_diacritics(text),
|
| 79 |
+
api_name="/infer_shakkala"
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
return text
|
| 83 |
+
|
| 84 |
+
css_style = """
|
| 85 |
+
body {
|
| 86 |
+
background-image: url('https://cdna.artstation.com/p/assets/images/images/074/776/904/large/pietro-chiovaro-r1-castle-chp.jpg?1712916847');
|
| 87 |
+
background-size: cover;
|
| 88 |
+
background-position: center;
|
| 89 |
+
color: #fff; /* General text color */
|
| 90 |
+
font-family: 'Arial', sans-serif;
|
| 91 |
+
}"""
|
| 92 |
|
| 93 |
# Create Gradio interface
|
| 94 |
demo = gr.Interface(
|
|
|
|
| 110 |
["علي البطل", "غابة سحرية", "Arabic"],
|
| 111 |
["Lila the Ladybug", "a garden full of flowers", "English"],
|
| 112 |
["ليلى الجنية", "حديقة مليئة بالأزهار", "Arabic"]
|
| 113 |
+
],
|
| 114 |
+
css = css_style,
|
| 115 |
)
|
| 116 |
|
| 117 |
# Launch the Gradio app
|