Upload 7 files
Browse files- .gitignore +3 -0
- CG_AI.iml +8 -0
- README.md +1 -0
- UI.py +75 -0
- misc.xml +4 -0
- modules.xml +8 -0
- workspace.xml +49 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
CG_AI.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="inheritedJdk" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
# Chhattisgrhi_AI
|
UI.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import asyncio
|
3 |
+
import torch
|
4 |
+
import streamlit as st
|
5 |
+
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
6 |
+
from googletrans import Translator
|
7 |
+
import langdetect
|
8 |
+
|
9 |
+
# ✅ Disable file watching for PyTorch compatibility with Streamlit
|
10 |
+
os.environ["STREAMLIT_WATCH_FILE_SYSTEM"] = "false"
|
11 |
+
|
12 |
+
# ✅ Fix for asyncio event loop crash on Windows
|
13 |
+
try:
|
14 |
+
asyncio.get_running_loop()
|
15 |
+
except RuntimeError:
|
16 |
+
asyncio.set_event_loop(asyncio.new_event_loop())
|
17 |
+
|
18 |
+
# ✅ Load Fine-Tuned Chhattisgarhi Translation Model
|
19 |
+
model_path = "chhattisgarhi_translator"
|
20 |
+
model = MBartForConditionalGeneration.from_pretrained(model_path)
|
21 |
+
tokenizer = MBart50TokenizerFast.from_pretrained(model_path, src_lang="hi_IN", tgt_lang="hne_IN")
|
22 |
+
translator = Translator()
|
23 |
+
|
24 |
+
# ✅ Detect Language
|
25 |
+
def detect_language(text):
|
26 |
+
try:
|
27 |
+
return langdetect.detect(text)
|
28 |
+
except:
|
29 |
+
return "unknown"
|
30 |
+
|
31 |
+
# ✅ Translate English → Hindi
|
32 |
+
def translate_english_to_hindi(text):
|
33 |
+
translated = translator.translate(text, src="en", dest="hi")
|
34 |
+
return translated.text
|
35 |
+
|
36 |
+
# ✅ Translate Hindi → Chhattisgarhi
|
37 |
+
def translate_hindi_to_chhattisgarhi(text):
|
38 |
+
sentences = text.split("।") # Sentence splitting
|
39 |
+
translated_sentences = []
|
40 |
+
|
41 |
+
for sentence in sentences:
|
42 |
+
sentence = sentence.strip()
|
43 |
+
if sentence:
|
44 |
+
inputs = tokenizer(sentence, return_tensors="pt", truncation=True, padding="longest", max_length=256)
|
45 |
+
with torch.no_grad():
|
46 |
+
translated_ids = model.generate(**inputs, max_length=256, num_beams=5, early_stopping=True)
|
47 |
+
translated_text = tokenizer.decode(translated_ids[0], skip_special_tokens=True)
|
48 |
+
translated_sentences.append(translated_text)
|
49 |
+
|
50 |
+
return " । ".join(translated_sentences)
|
51 |
+
|
52 |
+
# ✅ Streamlit UI
|
53 |
+
st.title("English/Hindi to Chhattisgarhi Translator 🗣️")
|
54 |
+
st.write("Enter an English or Hindi sentence and get its translation in Chhattisgarhi.")
|
55 |
+
|
56 |
+
user_input = st.text_area("Enter text:")
|
57 |
+
|
58 |
+
if st.button("Translate"):
|
59 |
+
if user_input.strip():
|
60 |
+
lang = detect_language(user_input)
|
61 |
+
|
62 |
+
if lang == "en":
|
63 |
+
hindi_text = translate_english_to_hindi(user_input)
|
64 |
+
chhattisgarhi_text = translate_hindi_to_chhattisgarhi(hindi_text)
|
65 |
+
st.success(f"**Hindi Translation**:\n{hindi_text}")
|
66 |
+
st.success(f"**Chhattisgarhi Translation**:\n{chhattisgarhi_text}")
|
67 |
+
|
68 |
+
elif lang == "hi":
|
69 |
+
chhattisgarhi_text = translate_hindi_to_chhattisgarhi(user_input)
|
70 |
+
st.success(f"**Chhattisgarhi Translation**:\n{chhattisgarhi_text}")
|
71 |
+
|
72 |
+
else:
|
73 |
+
st.error("❌ Unable to detect language. Please enter text in English or Hindi.")
|
74 |
+
else:
|
75 |
+
st.warning("⚠ Please enter some text before translating.")
|
misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/CG_AI.iml" filepath="$PROJECT_DIR$/.idea/CG_AI.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
workspace.xml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="AutoImportSettings">
|
4 |
+
<option name="autoReloadType" value="SELECTIVE" />
|
5 |
+
</component>
|
6 |
+
<component name="ChangeListManager">
|
7 |
+
<list default="true" id="e1157a84-ee63-4ab7-b24d-a01a2a59a7a8" name="Changes" comment="" />
|
8 |
+
<option name="SHOW_DIALOG" value="false" />
|
9 |
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
10 |
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
11 |
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
12 |
+
</component>
|
13 |
+
<component name="MarkdownSettingsMigration">
|
14 |
+
<option name="stateVersion" value="1" />
|
15 |
+
</component>
|
16 |
+
<component name="ProjectColorInfo"><![CDATA[{
|
17 |
+
"associatedIndex": 5
|
18 |
+
}]]></component>
|
19 |
+
<component name="ProjectId" id="30lKEO9s3RKvJURUZuQsiANbyKE" />
|
20 |
+
<component name="ProjectViewState">
|
21 |
+
<option name="hideEmptyMiddlePackages" value="true" />
|
22 |
+
<option name="showLibraryContents" value="true" />
|
23 |
+
</component>
|
24 |
+
<component name="PropertiesComponent"><![CDATA[{
|
25 |
+
"keyToString": {
|
26 |
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
27 |
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
28 |
+
"last_opened_file_path": "C:/Users/asus/Desktop/CG_AI"
|
29 |
+
}
|
30 |
+
}]]></component>
|
31 |
+
<component name="SharedIndexes">
|
32 |
+
<attachedChunks>
|
33 |
+
<set>
|
34 |
+
<option value="bundled-python-sdk-50da183f06c8-d3b881c8e49f-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-233.13135.95" />
|
35 |
+
</set>
|
36 |
+
</attachedChunks>
|
37 |
+
</component>
|
38 |
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
39 |
+
<component name="TaskManager">
|
40 |
+
<task active="true" id="Default" summary="Default task">
|
41 |
+
<changelist id="e1157a84-ee63-4ab7-b24d-a01a2a59a7a8" name="Changes" comment="" />
|
42 |
+
<created>1754196607008</created>
|
43 |
+
<option name="number" value="Default" />
|
44 |
+
<option name="presentableId" value="Default" />
|
45 |
+
<updated>1754196607008</updated>
|
46 |
+
</task>
|
47 |
+
<servers />
|
48 |
+
</component>
|
49 |
+
</project>
|