mohammad-shirkhani commited on
Commit
0f03fc1
1 Parent(s): f0c880a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -34
README.md CHANGED
@@ -1,33 +1,52 @@
1
- #Text-to-Image Pipeline in Persian
2
-
3
- Install Required Libraries
4
-
5
- !pip install transformers diffusers accelerate torch
6
-
7
- Import Necessary Libraries
8
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  import torch
10
  from transformers import MT5ForConditionalGeneration, T5Tokenizer
11
  from diffusers import StableDiffusionPipeline
12
 
13
- Set Device (GPU or CPU)
14
-
15
- # Determine the device: GPU if available, otherwise CPU
16
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
- print(f"Using device: {device}")
18
-
19
- Define and Load the Persian-to-Image Model Class
20
 
21
- # Define the model class
22
  class PersianToImageModel:
23
  def __init__(self, translation_model_name, image_model_name, device):
24
  self.device = device
25
 
26
- # Load translation model
27
  self.translation_model = MT5ForConditionalGeneration.from_pretrained(translation_model_name).to(device)
28
  self.translation_tokenizer = T5Tokenizer.from_pretrained(translation_model_name)
29
 
30
- # Load image generation model
31
  self.image_model = StableDiffusionPipeline.from_pretrained(image_model_name).to(device)
32
 
33
  def translate_text(self, persian_text):
@@ -41,30 +60,14 @@ class PersianToImageModel:
41
  return image
42
 
43
  def __call__(self, persian_text):
44
- # Translate Persian text to English
45
  english_text = self.translate_text(persian_text)
46
  print(f"Translated Text: {english_text}")
47
 
48
- # Generate and return image
49
  return self.generate_image(english_text)
50
 
51
- Instantiate the Model
52
-
53
- # Instantiate the combined model
54
  translation_model_name = 'mohammad-shirkhani/finetune_persian_to_english_mt5_base_summarize_on_celeba_hq'
55
  image_model_name = 'ebrahim-k/Stable-Diffusion-1_5-FT-celeba_HQ_en'
56
 
57
  persian_to_image_model = PersianToImageModel(translation_model_name, image_model_name, device)
58
 
59
- Example Usage of the Model
60
-
61
- from IPython.display import display
62
-
63
- persian_text = "این زن دارای موهای موج دار ، لب های بزرگ و موهای قهوه ای است و رژ لب دارد.این زن موهای موج دار و لب های بزرگ دارد و رژ لب دارد.فرد جذاب است و موهای موج دار ، چشم های باریک و موهای قهوه ای دارد."
64
- image = persian_to_image_model(persian_text)
65
- display(image)
66
-
67
-
68
- persian_text2 = "این مرد جذاب دارای موهای قهوه ای ، سوزش های جانبی ، دهان کمی باز و کیسه های زیر چشم است.این فرد جذاب دارای کیسه های زیر چشم ، سوزش های جانبی و دهان کمی باز است."
69
- image2 = persian_to_image_model(persian_text2)
70
- display(image2)
 
1
+ ---
2
+ license: cc-by-nc-sa-4.0
3
+ language:
4
+ - fa
5
+ - en
6
+ library_name: transformers
7
+ tags:
8
+ - text-to-image
9
+ - stable-diffusion
10
+ - transformers
11
+ pipeline_tag: text-to-image
12
+ co2_eq_emissions:
13
+ emissions: 200000
14
+ ---
15
+
16
+ <p align="center">
17
+ <img src="PersianToImage.jpg" alt="PersianToImage logo" width=200/>
18
+ </p>
19
+
20
+ # <span style="font-variant:small-caps;">PersianToImage</span>
21
+
22
+ <span style="font-variant:small-caps;">PersianToImage</span> is a unique pipeline that translates Persian text to English and generates corresponding images using a fine-tuned Stable Diffusion model. This tool is designed to easily convert descriptive Persian text into high-quality images, making it ideal for creative projects, visual content generation, and more.
23
+
24
+ ## Model Description
25
+
26
+ - **Developed by:** [Your Name](mailto:your.email@example.com)
27
+ - **Model type:** Text-to-Image generation
28
+ - **Languages:** Persian and English
29
+ - **License:** [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) (non-commercial use only)
30
+
31
+ ## How to Get Started with the Model
32
+
33
+ Use the code below to get started with the model.
34
+ Make sure you have installed <code><b>torch</b></code>, <code><b>diffusers</b></code>, <code><b>transformers</b></code>, and <code><b>accelerate</b></code> libraries.
35
+
36
+ ```python
37
  import torch
38
  from transformers import MT5ForConditionalGeneration, T5Tokenizer
39
  from diffusers import StableDiffusionPipeline
40
 
 
 
 
41
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
 
 
42
 
 
43
  class PersianToImageModel:
44
  def __init__(self, translation_model_name, image_model_name, device):
45
  self.device = device
46
 
 
47
  self.translation_model = MT5ForConditionalGeneration.from_pretrained(translation_model_name).to(device)
48
  self.translation_tokenizer = T5Tokenizer.from_pretrained(translation_model_name)
49
 
 
50
  self.image_model = StableDiffusionPipeline.from_pretrained(image_model_name).to(device)
51
 
52
  def translate_text(self, persian_text):
 
60
  return image
61
 
62
  def __call__(self, persian_text):
 
63
  english_text = self.translate_text(persian_text)
64
  print(f"Translated Text: {english_text}")
65
 
 
66
  return self.generate_image(english_text)
67
 
68
+ # Instantiate the model
 
 
69
  translation_model_name = 'mohammad-shirkhani/finetune_persian_to_english_mt5_base_summarize_on_celeba_hq'
70
  image_model_name = 'ebrahim-k/Stable-Diffusion-1_5-FT-celeba_HQ_en'
71
 
72
  persian_to_image_model = PersianToImageModel(translation_model_name, image_model_name, device)
73