Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ subprocess.run(
|
|
5 |
env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"},
|
6 |
shell=True
|
7 |
)
|
|
|
|
|
8 |
import os
|
9 |
import re
|
10 |
import time
|
@@ -12,6 +14,7 @@ import torch
|
|
12 |
import spaces
|
13 |
import gradio as gr
|
14 |
from threading import Thread
|
|
|
15 |
from transformers import (
|
16 |
AutoModelForCausalLM,
|
17 |
AutoTokenizer,
|
@@ -28,7 +31,6 @@ Writing Style:
|
|
28 |
|
29 |
1. Grammar Accuracy: Always ensure translations are grammatically correct.
|
30 |
|
31 |
-
|
32 |
2. Contextual Suitability: Tailor translations to the context and audience:
|
33 |
|
34 |
Use concise, clear sentences for medical and legal content.
|
@@ -37,12 +39,8 @@ Employ engaging, imaginative language for marketing material.
|
|
37 |
|
38 |
Preserve formality and eloquence for legal content.
|
39 |
|
40 |
-
|
41 |
-
|
42 |
3. Proper Structure: Respect Arabic sentence structures and avoid direct replication of source language grammar. Favor "الجملة الفعلية" unless "الجملة الاسمية" is more suitable (e.g., for headlines or disclaimers).
|
43 |
|
44 |
-
|
45 |
-
|
46 |
Style Choices:
|
47 |
|
48 |
Use diacritics only when necessary for clarity.
|
@@ -53,10 +51,8 @@ Transliterate names and drug names unless an Arabic equivalent exists.
|
|
53 |
|
54 |
Translate program, department, and agency names when beneficial.
|
55 |
|
56 |
-
|
57 |
Use Arabic numerals and ensure proper handling of units, addresses, and references.
|
58 |
|
59 |
-
|
60 |
Punctuation:
|
61 |
|
62 |
Apply Arabic punctuation rules, ensuring proper readability.
|
@@ -65,8 +61,6 @@ Use the Arabic comma (،) and semicolon (؛) as per conventions.
|
|
65 |
|
66 |
Avoid excessive use of quotation marks and ensure logical placement of colons (:).
|
67 |
|
68 |
-
|
69 |
-
|
70 |
Common Mistakes to Avoid:
|
71 |
|
72 |
Avoid translating "is" as "is considered" unless contextually appropriate.
|
@@ -77,7 +71,6 @@ Minimize repetitive structures; leverage pronouns where applicable.
|
|
77 |
|
78 |
Avoid overuse of constructions like "(قام + الفعل)" and "الخاص بـ."
|
79 |
|
80 |
-
|
81 |
Specific Terminology:
|
82 |
|
83 |
For legal translations, maintain formal tone and ensure accuracy in terminology.
|
@@ -86,14 +79,12 @@ For medical translations, simplify technical terms for lay audiences but retain
|
|
86 |
|
87 |
For marketing translations, prioritize creativity over literal translation, aligning with the core message.
|
88 |
|
89 |
-
|
90 |
Formatting Guidelines:
|
91 |
|
92 |
Consistently follow Arabic typographic standards.
|
93 |
|
94 |
Preserve the format of critical data (e.g., dates, measurements, and legal citations).
|
95 |
|
96 |
-
|
97 |
When in doubt, prioritize clarity, consistency, and alignment with the target audience's needs. Always reconcile project-specific instructions with these guidelines, giving precedence to client requirements when conflicts arise.
|
98 |
"""
|
99 |
# UI Configuration
|
@@ -271,6 +262,14 @@ def chat_response(
|
|
271 |
|
272 |
yield history, chat_display
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
def process_example(example: str) -> tuple:
|
275 |
"""Process example query and return empty history and updated display"""
|
276 |
return [], f"User: {example}\n\n"
|
|
|
5 |
env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"},
|
6 |
shell=True
|
7 |
)
|
8 |
+
subprocess.run('pip install googletrans==4.0.0-rc1', shell=True)
|
9 |
+
|
10 |
import os
|
11 |
import re
|
12 |
import time
|
|
|
14 |
import spaces
|
15 |
import gradio as gr
|
16 |
from threading import Thread
|
17 |
+
from googletrans import Translator
|
18 |
from transformers import (
|
19 |
AutoModelForCausalLM,
|
20 |
AutoTokenizer,
|
|
|
31 |
|
32 |
1. Grammar Accuracy: Always ensure translations are grammatically correct.
|
33 |
|
|
|
34 |
2. Contextual Suitability: Tailor translations to the context and audience:
|
35 |
|
36 |
Use concise, clear sentences for medical and legal content.
|
|
|
39 |
|
40 |
Preserve formality and eloquence for legal content.
|
41 |
|
|
|
|
|
42 |
3. Proper Structure: Respect Arabic sentence structures and avoid direct replication of source language grammar. Favor "الجملة الفعلية" unless "الجملة الاسمية" is more suitable (e.g., for headlines or disclaimers).
|
43 |
|
|
|
|
|
44 |
Style Choices:
|
45 |
|
46 |
Use diacritics only when necessary for clarity.
|
|
|
51 |
|
52 |
Translate program, department, and agency names when beneficial.
|
53 |
|
|
|
54 |
Use Arabic numerals and ensure proper handling of units, addresses, and references.
|
55 |
|
|
|
56 |
Punctuation:
|
57 |
|
58 |
Apply Arabic punctuation rules, ensuring proper readability.
|
|
|
61 |
|
62 |
Avoid excessive use of quotation marks and ensure logical placement of colons (:).
|
63 |
|
|
|
|
|
64 |
Common Mistakes to Avoid:
|
65 |
|
66 |
Avoid translating "is" as "is considered" unless contextually appropriate.
|
|
|
71 |
|
72 |
Avoid overuse of constructions like "(قام + الفعل)" and "الخاص بـ."
|
73 |
|
|
|
74 |
Specific Terminology:
|
75 |
|
76 |
For legal translations, maintain formal tone and ensure accuracy in terminology.
|
|
|
79 |
|
80 |
For marketing translations, prioritize creativity over literal translation, aligning with the core message.
|
81 |
|
|
|
82 |
Formatting Guidelines:
|
83 |
|
84 |
Consistently follow Arabic typographic standards.
|
85 |
|
86 |
Preserve the format of critical data (e.g., dates, measurements, and legal citations).
|
87 |
|
|
|
88 |
When in doubt, prioritize clarity, consistency, and alignment with the target audience's needs. Always reconcile project-specific instructions with these guidelines, giving precedence to client requirements when conflicts arise.
|
89 |
"""
|
90 |
# UI Configuration
|
|
|
262 |
|
263 |
yield history, chat_display
|
264 |
|
265 |
+
# Translate the final response to Arabic
|
266 |
+
translator = Translator()
|
267 |
+
translated_text = translator.translate(buffer, src='en', dest='ar').text
|
268 |
+
history[-1][1] = translated_text
|
269 |
+
chat_display = format_chat_history(history)
|
270 |
+
|
271 |
+
yield history, chat_display
|
272 |
+
|
273 |
def process_example(example: str) -> tuple:
|
274 |
"""Process example query and return empty history and updated display"""
|
275 |
return [], f"User: {example}\n\n"
|