Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,7 @@ import requests
|
|
3 |
import os
|
4 |
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
5 |
|
6 |
-
|
7 |
-
|
8 |
# API keys for other features (optional)
|
9 |
-
Transalate_token = os.getenv('Translate')
|
10 |
Image_Token = os.getenv('Image_generation')
|
11 |
Content_Token = os.getenv('ContentGeneration')
|
12 |
Image_prompt_token = os.getenv('Prompt_generation')
|
@@ -40,16 +37,18 @@ content_models = {
|
|
40 |
# Load the translation model and tokenizer locally
|
41 |
@st.cache_resource
|
42 |
def load_translation_model():
|
43 |
-
model
|
44 |
-
|
|
|
45 |
return model, tokenizer
|
46 |
|
47 |
# Function to perform translation locally
|
48 |
def translate_text_local(text):
|
49 |
model, tokenizer = load_translation_model()
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
53 |
return translated_text
|
54 |
|
55 |
# Function to query Groq content generation model (optional)
|
@@ -78,9 +77,9 @@ def generate_image_prompt(english_text):
|
|
78 |
"model": "mixtral-8x7b-32768",
|
79 |
"messages": [
|
80 |
{"role": "system", "content": "You are a professional Text to image prompt generator."},
|
81 |
-
{"role": "user", "content": f"Create a text to image generation prompt about {english_text} within
|
82 |
],
|
83 |
-
"max_tokens":
|
84 |
}
|
85 |
response = requests.post("https://api.groq.com/openai/v1/chat/completions", json=payload, headers=Image_Prompt)
|
86 |
if response.status_code == 200:
|
@@ -105,41 +104,27 @@ def show_user_guide():
|
|
105 |
st.title("FusionMind User Guide")
|
106 |
st.write("""
|
107 |
### Welcome to the FusionMind User Guide!
|
108 |
-
|
109 |
### How to use this app:
|
110 |
-
|
111 |
1. **Input Tamil Text**:
|
112 |
- You can either select one of the suggested Tamil phrases or input your own text. The app primarily focuses on Tamil inputs, but it supports a wide range of other languages as well (see the list below).
|
113 |
-
|
114 |
2. **Generate Translations**:
|
115 |
- Once you've input your text, the app will automatically translate it to English. The translation model is a **many-to-one model**, meaning it can take input from various languages and translate it into English.
|
116 |
-
|
117 |
3. **Generate Educational Content**:
|
118 |
- After translating the text into English, the app will generate **educational content** based on the translated input. You can adjust the creativity of the content generation using the temperature slider, and control the length of the output with the token limit setting.
|
119 |
-
|
120 |
4. **Generate Images**:
|
121 |
- In addition to generating content, the app can also generate an **image** related to the translated content. You don’t need to worry about creating complex image prompts—FusionMind includes an automatic **image prompt generator** that will convert your input into a well-defined image prompt, ensuring better image generation results.
|
122 |
-
|
123 |
---
|
124 |
-
|
125 |
### Features:
|
126 |
-
|
127 |
- **Multilingual Translation**:
|
128 |
- FusionMind supports a **many-to-one translation model**, so you can input text in a wide variety of languages, not just Tamil. Below are the supported languages:
|
129 |
-
|
130 |
- **Arabic (ar_AR)**, **Czech (cs_CZ)**, **German (de_DE)**, **English (en_XX)**, **Spanish (es_XX)**, **Estonian (et_EE)**, **Finnish (fi_FI)**, **French (fr_XX)**, **Gujarati (gu_IN)**, **Hindi (hi_IN)**, **Italian (it_IT)**, **Japanese (ja_XX)**, **Kazakh (kk_KZ)**, **Korean (ko_KR)**, **Lithuanian (lt_LT)**, **Latvian (lv_LV)**, **Burmese (my_MM)**, **Nepali (ne_NP)**, **Dutch (nl_XX)**, **Romanian (ro_RO)**, **Russian (ru_RU)**, **Sinhala (si_LK)**, **Turkish (tr_TR)**, **Vietnamese (vi_VN)**, **Chinese (zh_CN)**, **Afrikaans (af_ZA)**, **Azerbaijani (az_AZ)**, **Bengali (bn_IN)**, **Persian (fa_IR)**, **Hebrew (he_IL)**, **Croatian (hr_HR)**, **Indonesian (id_ID)**, **Georgian (ka_GE)**, **Khmer (km_KH)**, **Macedonian (mk_MK)**, **Malayalam (ml_IN)**, **Mongolian (mn_MN)**, **Marathi (mr_IN)**, **Polish (pl_PL)**, **Pashto (ps_AF)**, **Portuguese (pt_XX)**, **Swedish (sv_SE)**, **Swahili (sw_KE)**, **Tamil (ta_IN)**, **Telugu (te_IN)**, **Thai (th_TH)**, **Tagalog (tl_XX)**, **Ukrainian (uk_UA)**, **Urdu (ur_PK)**, **Xhosa (xh_ZA)**, **Galician (gl_ES)**, **Slovene (sl_SI)**.
|
131 |
-
|
132 |
- **Temperature Adjustment**:
|
133 |
- You can adjust the **temperature** of the content generation. A **higher temperature** makes the content more creative and varied, while a **lower temperature** generates more focused and deterministic responses.
|
134 |
-
|
135 |
- **Token Limit**:
|
136 |
- Set the **maximum number of tokens** for content generation. This allows you to control the length of the generated educational content.
|
137 |
-
|
138 |
- **Auto-Generated Image Prompts**:
|
139 |
- One of the unique features of FusionMind is the **auto-generated image prompts**. Even if you're not experienced in creating detailed prompts for image generation, the app will take care of this for you. It automatically converts the translated text or content into a well-defined prompt that produces more accurate and high-quality images.
|
140 |
-
|
141 |
---
|
142 |
-
|
143 |
Enjoy the multimodal experience with **FusionMind** and explore its powerful translation, content generation, and image generation features!
|
144 |
""")
|
145 |
|
@@ -198,4 +183,4 @@ def main():
|
|
198 |
st.image(image_data, caption="Generated Image")
|
199 |
|
200 |
if __name__ == "__main__":
|
201 |
-
main()
|
|
|
3 |
import os
|
4 |
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
5 |
|
|
|
|
|
6 |
# API keys for other features (optional)
|
|
|
7 |
Image_Token = os.getenv('Image_generation')
|
8 |
Content_Token = os.getenv('ContentGeneration')
|
9 |
Image_prompt_token = os.getenv('Prompt_generation')
|
|
|
37 |
# Load the translation model and tokenizer locally
|
38 |
@st.cache_resource
|
39 |
def load_translation_model():
|
40 |
+
with st.spinner('Loading translation model... Please wait.If you are here for First Time it takes 2 Mins to Please wait'):
|
41 |
+
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-many-to-one-mmt")
|
42 |
+
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-many-to-one-mmt")
|
43 |
return model, tokenizer
|
44 |
|
45 |
# Function to perform translation locally
|
46 |
def translate_text_local(text):
|
47 |
model, tokenizer = load_translation_model()
|
48 |
+
with st.spinner('Translation is on progress.If you are here for First Time it takes 2 Mins to Please wait'):
|
49 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True)
|
50 |
+
translated_tokens = model.generate(**inputs, forced_bos_token_id=tokenizer.lang_code_to_id["en_XX"])
|
51 |
+
translated_text = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
52 |
return translated_text
|
53 |
|
54 |
# Function to query Groq content generation model (optional)
|
|
|
77 |
"model": "mixtral-8x7b-32768",
|
78 |
"messages": [
|
79 |
{"role": "system", "content": "You are a professional Text to image prompt generator."},
|
80 |
+
{"role": "user", "content": f"Create a text to image generation prompt about {english_text} within 150 tokens."}
|
81 |
],
|
82 |
+
"max_tokens": 150
|
83 |
}
|
84 |
response = requests.post("https://api.groq.com/openai/v1/chat/completions", json=payload, headers=Image_Prompt)
|
85 |
if response.status_code == 200:
|
|
|
104 |
st.title("FusionMind User Guide")
|
105 |
st.write("""
|
106 |
### Welcome to the FusionMind User Guide!
|
|
|
107 |
### How to use this app:
|
|
|
108 |
1. **Input Tamil Text**:
|
109 |
- You can either select one of the suggested Tamil phrases or input your own text. The app primarily focuses on Tamil inputs, but it supports a wide range of other languages as well (see the list below).
|
|
|
110 |
2. **Generate Translations**:
|
111 |
- Once you've input your text, the app will automatically translate it to English. The translation model is a **many-to-one model**, meaning it can take input from various languages and translate it into English.
|
|
|
112 |
3. **Generate Educational Content**:
|
113 |
- After translating the text into English, the app will generate **educational content** based on the translated input. You can adjust the creativity of the content generation using the temperature slider, and control the length of the output with the token limit setting.
|
|
|
114 |
4. **Generate Images**:
|
115 |
- In addition to generating content, the app can also generate an **image** related to the translated content. You don’t need to worry about creating complex image prompts—FusionMind includes an automatic **image prompt generator** that will convert your input into a well-defined image prompt, ensuring better image generation results.
|
|
|
116 |
---
|
|
|
117 |
### Features:
|
|
|
118 |
- **Multilingual Translation**:
|
119 |
- FusionMind supports a **many-to-one translation model**, so you can input text in a wide variety of languages, not just Tamil. Below are the supported languages:
|
|
|
120 |
- **Arabic (ar_AR)**, **Czech (cs_CZ)**, **German (de_DE)**, **English (en_XX)**, **Spanish (es_XX)**, **Estonian (et_EE)**, **Finnish (fi_FI)**, **French (fr_XX)**, **Gujarati (gu_IN)**, **Hindi (hi_IN)**, **Italian (it_IT)**, **Japanese (ja_XX)**, **Kazakh (kk_KZ)**, **Korean (ko_KR)**, **Lithuanian (lt_LT)**, **Latvian (lv_LV)**, **Burmese (my_MM)**, **Nepali (ne_NP)**, **Dutch (nl_XX)**, **Romanian (ro_RO)**, **Russian (ru_RU)**, **Sinhala (si_LK)**, **Turkish (tr_TR)**, **Vietnamese (vi_VN)**, **Chinese (zh_CN)**, **Afrikaans (af_ZA)**, **Azerbaijani (az_AZ)**, **Bengali (bn_IN)**, **Persian (fa_IR)**, **Hebrew (he_IL)**, **Croatian (hr_HR)**, **Indonesian (id_ID)**, **Georgian (ka_GE)**, **Khmer (km_KH)**, **Macedonian (mk_MK)**, **Malayalam (ml_IN)**, **Mongolian (mn_MN)**, **Marathi (mr_IN)**, **Polish (pl_PL)**, **Pashto (ps_AF)**, **Portuguese (pt_XX)**, **Swedish (sv_SE)**, **Swahili (sw_KE)**, **Tamil (ta_IN)**, **Telugu (te_IN)**, **Thai (th_TH)**, **Tagalog (tl_XX)**, **Ukrainian (uk_UA)**, **Urdu (ur_PK)**, **Xhosa (xh_ZA)**, **Galician (gl_ES)**, **Slovene (sl_SI)**.
|
|
|
121 |
- **Temperature Adjustment**:
|
122 |
- You can adjust the **temperature** of the content generation. A **higher temperature** makes the content more creative and varied, while a **lower temperature** generates more focused and deterministic responses.
|
|
|
123 |
- **Token Limit**:
|
124 |
- Set the **maximum number of tokens** for content generation. This allows you to control the length of the generated educational content.
|
|
|
125 |
- **Auto-Generated Image Prompts**:
|
126 |
- One of the unique features of FusionMind is the **auto-generated image prompts**. Even if you're not experienced in creating detailed prompts for image generation, the app will take care of this for you. It automatically converts the translated text or content into a well-defined prompt that produces more accurate and high-quality images.
|
|
|
127 |
---
|
|
|
128 |
Enjoy the multimodal experience with **FusionMind** and explore its powerful translation, content generation, and image generation features!
|
129 |
""")
|
130 |
|
|
|
183 |
st.image(image_data, caption="Generated Image")
|
184 |
|
185 |
if __name__ == "__main__":
|
186 |
+
main()
|