NadaAljohani commited on
Commit
755043b
1 Parent(s): 6166a91

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +227 -13
README.md CHANGED
@@ -1,13 +1,227 @@
1
- ---
2
- title: PoemGen
3
- emoji: 🏆
4
- colorFrom: purple
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 4.44.0
8
- app_file: app.py
9
- pinned: false
10
- short_description: This project integrates several AI tasks
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Final-Project-Tuwaiq-Generative-AI
2
+ # PoemGen: AI Poem Generation Project
3
+
4
+ This project integrates several generative Artificial Intelligence tasks, including text generation, text-to-speech, translation, and text-to-image, using models from Hugging Face's Transformers library.
5
+
6
+ The project allows users to generate poems in both Arabic and English based on their input, converts the text to speech, translates Arabic input into English to support text-to-image generation, and produces images that capture the essence of the poem.
7
+
8
+
9
+ ## Aim
10
+
11
+ The aim of this project is to:
12
+ 1. Generate poems in both Arabic and English based on user input.
13
+ 2. Convert the generated poems into speech in their respective languages.
14
+ 3. Translate Arabic poems into English to support image generation.
15
+ 4. Generate images that visually represent the essence of the generated poem.
16
+
17
+
18
+ ## Hugging Face Space Link
19
+
20
+ You can try the project on Hugging Face: [PoemGen](https://huggingface.co/spaces/SarahMarzouq/PoemGen)
21
+
22
+
23
+ ## Models
24
+
25
+ 1. **Text Generation**:
26
+ - Arabic poem generation using the [**akhooli/ap2023**](https://huggingface.co/akhooli/ap2023) model.
27
+ - English poem generation using the [**ashiqabdulkhader/GPT2-Poet**](https://huggingface.co/ashiqabdulkhader/GPT2-Poet) model.
28
+
29
+ 2. **Text-to-Speech**:
30
+ - Converts Arabic poems to speech using the [**facebook/mms-tts-ara**](https://huggingface.co/facebook/mms-tts-ara) model.
31
+ - Converts English poems to speech using the [**microsoft/speecht5_tts**](https://huggingface.co/microsoft/speecht5_tts) model.
32
+
33
+ 3. **Translation**:
34
+ - Arabic poems are translated into English using the [**Helsinki-NLP/opus-mt-ar-en**](https://huggingface.co/Helsinki-NLP/opus-mt-ar-en) model.
35
+
36
+ 4. **Text-to-Image**:
37
+ - Generates an image based on the generated poem using the [**runwayml/stable-diffusion-v1-5**](https://huggingface.co/runwayml/stable-diffusion-v1-5) model.
38
+
39
+
40
+ ## Why We Chose These Models
41
+
42
+ ### Text Generation:
43
+
44
+ - **Arabic Poem Generation**:
45
+ We chose the [**akhooli/ap2023**](https://huggingface.co/akhooli/ap2023) model for Arabic poem generation because the availability of high-quality Arabic poem generator models is limited, and many existing models lack consistency. This model stood out as the best option to support our idea compared to others.
46
+
47
+ - **English Poem Generation**:
48
+ We chose the [**ashiqabdulkhader/GPT2-Poet**](https://huggingface.co/ashiqabdulkhader/GPT2-Poet) model. Although there is also a lack of high-quality English poem generation models, this one was the best among the available options. While it can generate poems as expected, it sometimes lacks coherence in meaning. However, compared to other models, it provided the most reliable results.
49
+
50
+ These models are pre-trained for creative text generation, making them ideal for producing meaningful and artistic poems.
51
+
52
+
53
+ ### Text-to-Speech:
54
+
55
+ - **Arabic Text-to-Speech**:
56
+ The [**facebook/mms-tts-ara**](https://huggingface.co/facebook/mms-tts-ara) model was selected for Arabic text-to-speech. After evaluating multiple Text-to-Speech models for Arabic, this one provided superior pronunciation and clarity compared to the others.
57
+
58
+ - **English Text-to-Speech**:
59
+ The [**microsoft/speecht5_tts**](https://huggingface.co/microsoft/speecht5_tts) model, developed by Microsoft, was selected for English text-to-speech due to its high-quality pronunciation and clarity. Being from Microsoft, we are confident that this model benefits from state-of-the-art technology and is highly reliable for generating natural and clear speech, making it the best choice for our project.
60
+
61
+ Both models will enhance the user experience by providing an enjoyable listening experience for the generated poems.
62
+
63
+
64
+ ### Text Translation:
65
+
66
+ Since the image generation model (**runwayml/stable-diffusion-v1-5**) does not support Arabic—primarily focusing on text-to-image generation using English-language prompts—we use the [**Helsinki-NLP/opus-mt-ar-en**](https://huggingface.co/Helsinki-NLP/opus-mt-ar-en) model to translate Arabic poems into English. This ensures that the model can interpret the text effectively and generate accurate images based on the translation. We chose this model as it is one of the most downloaded and highly rated models on Hugging Face specifically for translating Arabic to English.
67
+
68
+
69
+ ### Text-to-Image:
70
+
71
+ The [**runwayml/stable-diffusion-v1-5**](https://huggingface.co/runwayml/stable-diffusion-v1-5) model was chosen for its superior ability to generate detailed and relevant images from textual descriptions. Its advanced capabilities in interpreting prompts enable it to create visually striking and contextually appropriate images based on poems.
72
+
73
+
74
+ ## Limitations
75
+
76
+ - **Poem Generation Quality**:
77
+ The models used to generate poems do not always produce fluent or aesthetically pleasing text. In Arabic, the output is often fragmented and requires significant post-processing to improve readability and coherence.
78
+
79
+ - **Image Generation from Arabic**:
80
+ The models that convert Arabic texts into images are limited, and they require a large GPU to function efficiently. Additionally, translation from Arabic to English may not always capture the full poetic nuance or cultural references, which can negatively impact the accuracy and overall quality of the image generation process.
81
+
82
+ - **Arabic Text-to-Speech Issues**:
83
+ The Arabic text-to-speech model struggles to complete sentences, particularly in Classical Arabic, and often mispronounces or skips certain words. It sometimes stops before finishing a full sentence, resulting in cut-off output. Additionally, it does not handle Arabic text as fluently as the English text-to-speech model.
84
+
85
+ - **Random Termination in Text Generation**:
86
+ All text generation models tend to end abruptly and randomly at incomplete points, without concluding the poem naturally. This results in unfinished sentences or thoughts, which diminishes the overall quality of the generated poems.
87
+
88
+
89
+ ## Special Measures Taken to Support the Arabic Language
90
+
91
+ To ensure that Arabic input can be used effectively with models that primarily support English, we implemented a translation step after generating the poem in Arabic. Once the Arabic poem is created, it is translated into English using the [**Helsinki-NLP/opus-mt-ar-en**](https://huggingface.co/Helsinki-NLP/opus-mt-ar-en) model. The translated text is then used for image generation, as the image model [**runwayml/stable-diffusion-v1-5**](https://huggingface.co/runwayml/stable-diffusion-v1-5) only accepts English text inputs.
92
+
93
+ This approach allows us to incorporate Arabic-language inputs into the project while still utilizing powerful image generation models that are limited to English. However, it's important to note that the translation may not always capture the full nuance or cultural context of the original Arabic poem, which could influence the accuracy and relevance of the generated image.
94
+
95
+
96
+ ## Dependencies
97
+
98
+ To run the project, the following Python packages are required:
99
+
100
+ - **transformers**
101
+ - **gradio**
102
+ - **torch**
103
+ - **uvicorn**
104
+ - **datasets**
105
+ - **diffusers**
106
+
107
+ Install these dependencies using pip:
108
+
109
+ bash
110
+ pip install transformers gradio torch datasets diffusers
111
+
112
+
113
+ ## Functions
114
+
115
+ 1. *Primary Function: generate_poem*:
116
+ This function receives 2 inputs from the Gradio interface, executes the following functions, and returns 3 outputs:
117
+ - The generated poem.
118
+ - The audio.
119
+ - The image.
120
+
121
+ 2. *Poem Generation Functions: generate_poem_arabic and generate_poem_english*:
122
+ These functions are responsible for generating a poem (text) in Arabic or English, based on the provided text.
123
+ - The `generate_poem_arabic` function generates an Arabic poem.
124
+ - The `generate_poem_english` function generates an English poem.
125
+
126
+ 3. *Audio Functions: text_to_speech_arabic and text_to_speech_english*:
127
+ These functions are responsible for generating audio in Arabic or English, based on the provided text.
128
+ - The `text_to_speech_arabic` function converts Arabic text to speech.
129
+ - The `text_to_speech_english` function converts English text to speech.
130
+
131
+ 4. *Image Function: generate_image_from_poem*:
132
+ This function is responsible for generating an image based on poem.
133
+
134
+ 5. *Translation Function: translate_arabic_to_english*:
135
+ This function is responsible for translating the Arabic poem to English to be used for the image function, which accepts only English inputs.
136
+
137
+
138
+ ## Gradio Interface:
139
+
140
+ The Gradio interface enables you to choose the language for the poem, either Arabic or English. You can then provide a text (sentence) as a starting point for the poem. The entire poem will be in the context of the provided text (sentence).
141
+
142
+ ### Expected Results:
143
+ 1. The generated poem.
144
+ 2. Audio reading the poem.
145
+ 3. An image capturing the essence of the poem.
146
+
147
+ - The Gradio interface uses the primary function `generate_poem`, has predefined examples, features a custom CSS style, and can be launched with `my_model.launch()`.
148
+
149
+
150
+ ## Running the Project
151
+ You can run the code either locally or on a cloud-based platform (such as Google Colab or Jupyter Notebook).
152
+
153
+ To run the project locally, follow these steps:
154
+
155
+ 1. Clone or download the project.
156
+ 2. Install the required dependencies (refer to the **Dependencies** section).
157
+ 3. Execute the Notebook
158
+
159
+ Ensure you have installed the required libraries listed in the requirements.txt file before running the Notebook.
160
+
161
+
162
+ This will open a Gradio UI where you can select the language (Arabic or English), input a sentence, and generate the following outputs:
163
+
164
+ - A poem.
165
+ - Audio of the generated poem.
166
+ - An image.
167
+
168
+
169
+ ## Expected Output
170
+
171
+ Below are the expected outputs for both English and Arabic poem generation, including the generated text, text-to-speech output, translation (if applicable), and the generated image based on the input.
172
+
173
+ ### Example 1: English Poem
174
+
175
+ #### Input:
176
+ Language : "Englsih"
177
+ Sentence (Text) : "The shining sun rises over the calm ocean"
178
+
179
+ #### Output:
180
+ 1. **Generated Poem:**
181
+ The shining sun rises over the calm ocean,
182
+ A golden light that touches every motion.
183
+ Waves gently dance under the sky so clear,
184
+ A morning melody for all to hear.
185
+ Dreams awaken with the break of day,
186
+ As sunlight whispers in a soft display.
187
+
188
+ 2. **Text-to-Speech:**
189
+ The poem will be converted into English speech using the microsoft/speecht5_tts model, producing natural and clear audio for the generated poem.
190
+
191
+ 3. **Generated Image:**
192
+ An image of a tranquil ocean scene, with the sun rising over calm waters, gently touching the waves. The image will reflect the peaceful and serene environment described in the poem.
193
+
194
+ ### Example 2: Arabic Poem
195
+
196
+ #### Input:
197
+ Language : "Arabic"
198
+ Sentence (Text) : "الورود تتفتح في الربيع"
199
+
200
+ #### Output:
201
+ 1. **Generated Poem:**
202
+ الورود تتفتح في الربيع،
203
+ بألوان تملأ الفضاء الواسع.
204
+ عبيرها يفوح مع النسيم العليل،
205
+ ليغني أغنية الفجر الجميل.
206
+ الأرض ترتدي ثوب الأزهار،
207
+ في موسم الحب والأنوار.
208
+
209
+ 2. **Text-to-Speech:**
210
+ The poem will be converted into Arabic speech using the [**facebook/mms-tts-ara**](https://huggingface.co/facebook/mms-tts-ara).
211
+
212
+ 3. **Translation for Image Generation:**
213
+ Since the image model [**runwayml/stable-diffusion-v1-5**](https://huggingface.co/runwayml/stable-diffusion-v1-5) only supports English input, the Arabic poem will be translated into English using the [**Helsinki-NLP/opus-mt-ar-en**](https://huggingface.co/Helsinki-NLP/opus-mt-ar-en) model:
214
+
215
+ The flowers bloom in spring,
216
+ With colors filling the wide space.
217
+ Their fragrance spreads with the gentle breeze,
218
+ Singing the song of a beautiful dawn.
219
+ The earth wears a dress of flowers,
220
+ In the season of love and lights.
221
+
222
+ 4. **Generated Image:**
223
+ An image of blooming flowers in a vibrant spring setting, with colorful blossoms filling the scene.
224
+
225
+
226
+ ## Video and Slides:
227
+ A video and Slides demonstrating the project has been uploaded to the repository. You can view it for a better understanding of the project. You can find it in the [`video/`](./video) directory as `demo_video.mp4`. and [`slides/`](./slides) directory as `PoemGen_compressed.pdf`.