Update README.md
Browse files
README.md
CHANGED
|
@@ -9,138 +9,88 @@ app_file: app.py
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# AI-Powered Bilingual Storyteller & Illustrator
|
| 13 |
-
|
| 14 |
-
##
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
##
|
| 19 |
-
|
| 20 |
-
###
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
- **
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
- **
|
| 29 |
-
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
- Template-based system with curated high-quality narratives
|
| 53 |
-
- Dynamic template selection based on prompt analysis
|
| 54 |
-
- Parameter extraction to customize stories
|
| 55 |
-
- Multiple fallback mechanisms to ensure appropriate content
|
| 56 |
-
|
| 57 |
-
3. **Emotion Analysis**:
|
| 58 |
-
- English: distilbert-based sentiment analysis
|
| 59 |
-
- Arabic: CAMeL-Lab/bert-base-arabic-sentiment when available
|
| 60 |
-
- Cross-lingual sentiment analysis for comprehensive coverage
|
| 61 |
-
|
| 62 |
-
4. **Translation Capabilities**:
|
| 63 |
-
- Arabic-to-English: Helsinki-NLP/opus-mt-ar-en
|
| 64 |
-
- English-to-Arabic: Helsinki-NLP/opus-mt-en-ar (when available)
|
| 65 |
-
- Used for cross-lingual operations and image generation
|
| 66 |
|
| 67 |
### Visual Generation
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
- Scene extraction from story content
|
| 73 |
-
- Style-specific prompt enhancement
|
| 74 |
-
- Comprehensive error handling
|
| 75 |
-
|
| 76 |
-
## Usage Instructions
|
| 77 |
-
|
| 78 |
-
### Basic Story Generation
|
| 79 |
-
1. Enter a prompt in English or Arabic
|
| 80 |
-
2. Select your desired output language
|
| 81 |
-
3. Click "Generate Story"
|
| 82 |
-
4. Review your story with emotional analysis
|
| 83 |
-
|
| 84 |
-
### Template Story Creation
|
| 85 |
-
1. Choose a template type (Adventure, Friendship, Fantasy)
|
| 86 |
-
2. Fill in the template parameters or use defaults
|
| 87 |
-
3. Select output language
|
| 88 |
-
4. Generate your customized story
|
| 89 |
-
|
| 90 |
-
### Visual Storytelling
|
| 91 |
-
1. Enter your story prompt
|
| 92 |
-
2. Choose output language
|
| 93 |
-
3. Select the number of scenes (1-5)
|
| 94 |
-
4. Pick your preferred artistic style
|
| 95 |
-
5. Generate a story with matching illustrations
|
| 96 |
-
|
| 97 |
-
## Template System
|
| 98 |
-
|
| 99 |
-
The application includes a sophisticated template system with:
|
| 100 |
|
| 101 |
-
|
| 102 |
-
-
|
| 103 |
-
-
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
-
##
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
|
| 122 |
## Technical Requirements
|
| 123 |
-
|
| 124 |
- Python 3.8+
|
| 125 |
-
- CUDA-capable GPU
|
| 126 |
-
-
|
| 127 |
-
|
| 128 |
-
## Future Enhancements
|
| 129 |
-
|
| 130 |
-
- Enhanced Arabic image prompt understanding
|
| 131 |
-
- Voice narration for stories
|
| 132 |
-
- Interactive branching narratives
|
| 133 |
-
- Additional language support
|
| 134 |
-
- Expanded template library
|
| 135 |
-
|
| 136 |
-
## License & Acknowledgements
|
| 137 |
-
|
| 138 |
-
- [Hugging Face Transformers](https://github.com/huggingface/transformers)
|
| 139 |
-
- [Diffusers](https://github.com/huggingface/diffusers)
|
| 140 |
-
- [CAMeL-Lab](https://huggingface.co/CAMeL-Lab)
|
| 141 |
-
- [Gradio](https://github.com/gradio-app/gradio)
|
| 142 |
-
- [Helsinki-NLP](https://huggingface.co/Helsinki-NLP)
|
| 143 |
-
|
| 144 |
-
## Contact
|
| 145 |
-
|
| 146 |
-
For questions or support, please open an issue in the repository.
|
|
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# AI-Powered Bilingual Storyteller & Illustrator - Technical Summary
|
| 13 |
+
|
| 14 |
+
## Core Functionality
|
| 15 |
+
- Generates stories in English and Arabic with emotional analysis and optional illustrations
|
| 16 |
+
- Uses template-based approach with AI models to ensure quality and safety
|
| 17 |
+
|
| 18 |
+
## Technical Architecture
|
| 19 |
+
|
| 20 |
+
### Story Generation
|
| 21 |
+
|
| 22 |
+
#### NLP Pipelines
|
| 23 |
+
- **English Text Generation Pipeline**:
|
| 24 |
+
```python
|
| 25 |
+
pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B", device="cpu")
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
- **Arabic Generation**:
|
| 29 |
+
```python
|
| 30 |
+
# Uses MT5 instead of standard pipeline
|
| 31 |
+
AutoTokenizer.from_pretrained("google/mt5-small")
|
| 32 |
+
AutoModelForSeq2SeqLM.from_pretrained("google/mt5-small")
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
- **Sentiment Analysis Pipelines**:
|
| 36 |
+
```python
|
| 37 |
+
# English
|
| 38 |
+
pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english", device="cpu")
|
| 39 |
+
|
| 40 |
+
# Arabic
|
| 41 |
+
pipeline("sentiment-analysis", model="CAMeL-Lab/bert-base-arabic-sentiment", device="cpu")
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
- **Translation Pipelines**:
|
| 45 |
+
```python
|
| 46 |
+
# Arabic to English
|
| 47 |
+
pipeline("translation", model="Helsinki-NLP/opus-mt-ar-en", device="cpu")
|
| 48 |
+
|
| 49 |
+
# English to Arabic
|
| 50 |
+
pipeline("translation", model="Helsinki-NLP/opus-mt-en-ar", device="cpu")
|
| 51 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
### Visual Generation
|
| 54 |
+
- **Image Generation Pipeline**:
|
| 55 |
+
```python
|
| 56 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 57 |
+
"runwayml/stable-diffusion-v1-5",
|
| 58 |
+
torch_dtype=torch.float16
|
| 59 |
+
)
|
| 60 |
+
```
|
| 61 |
+
- Efficient GPU resource management via @spaces.GPU decorator
|
| 62 |
- Scene extraction from story content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
### Content Safety System
|
| 65 |
+
- Multi-layered content filtering
|
| 66 |
+
- Regex pattern detection for inappropriate content
|
| 67 |
+
- Repetition detection (unique word ratio < 0.4)
|
| 68 |
+
- Fallback mechanisms to reliable templates
|
| 69 |
|
| 70 |
+
## Implementation Highlights
|
| 71 |
|
| 72 |
+
### MultilingualStoryGenerator Class
|
| 73 |
+
- Central class managing generation in both languages
|
| 74 |
+
- Handles language detection, content safety, and sentiment analysis
|
| 75 |
+
- Template selection logic based on keyword matching
|
| 76 |
+
- Parameter extraction from prompts
|
| 77 |
|
| 78 |
+
### Story Templates
|
| 79 |
+
- Three categories: Adventure, Friendship, Fantasy
|
| 80 |
+
- Multiple variations in both languages
|
| 81 |
+
- Dynamic parameter filling
|
| 82 |
|
| 83 |
+
### GPU Resource Management
|
| 84 |
+
- @spaces.GPU decorator for efficient GPU allocation
|
| 85 |
+
- Pipeline moved to GPU only when needed for image generation
|
| 86 |
+
- Proper cleanup with torch.cuda.empty_cache() and gc.collect()
|
| 87 |
|
| 88 |
+
### Error Handling
|
| 89 |
+
- Comprehensive logging system
|
| 90 |
+
- Graceful degradation for missing components
|
| 91 |
+
- Multiple fallback mechanisms
|
| 92 |
|
| 93 |
## Technical Requirements
|
|
|
|
| 94 |
- Python 3.8+
|
| 95 |
+
- CUDA-capable GPU (for image generation)
|
| 96 |
+
- Key dependencies: transformers, diffusers, gradio, torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|