Spaces:
Running
Running
add upgrade model version
Browse files- .env +2 -1
- translate/translator.py +1 -1
- utils/utils.py +5 -3
- word/word_helper.py +1 -1
.env
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
GEMINI_API_KEY = AIzaSyDIPbH7zKoeTS5aKMQuMjzBBiVlWadcmr8
|
2 |
-
MONGODB_URI = mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
|
|
|
|
1 |
GEMINI_API_KEY = AIzaSyDIPbH7zKoeTS5aKMQuMjzBBiVlWadcmr8
|
2 |
+
MONGODB_URI = mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
|
3 |
+
MODEL_VERSION = gemini-2.0-flash-lite
|
translate/translator.py
CHANGED
@@ -21,7 +21,7 @@ def translate_text_dict(text_dict: Dict[str, List[str]], source_lang: str = "vi
|
|
21 |
Return the translated texts formatted like the original dictionary. Do NOT say anthing else. Return it as a JSON block."""
|
22 |
|
23 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
24 |
-
model = genai.GenerativeModel(
|
25 |
|
26 |
response = model.generate_content(prompt) # Use a model appropriate for your needs and API key. gemini-2.0-flash doesn't exist. 1.5-pro is a good general-purpose model.
|
27 |
|
|
|
21 |
Return the translated texts formatted like the original dictionary. Do NOT say anthing else. Return it as a JSON block."""
|
22 |
|
23 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
24 |
+
model = genai.GenerativeModel(os.getenv("MODEL_VERSION"))
|
25 |
|
26 |
response = model.generate_content(prompt) # Use a model appropriate for your needs and API key. gemini-2.0-flash doesn't exist. 1.5-pro is a good general-purpose model.
|
27 |
|
utils/utils.py
CHANGED
@@ -7,8 +7,10 @@ import json
|
|
7 |
import time
|
8 |
from google.api_core.exceptions import ResourceExhausted
|
9 |
import re
|
|
|
|
|
10 |
|
11 |
-
genai.configure(
|
12 |
|
13 |
|
14 |
def unzip_office_file(pptx_file: io.BytesIO):
|
@@ -34,7 +36,7 @@ def translate_single_text(text: str, source_lang: str = 'English', target_lang:
|
|
34 |
retries = 0
|
35 |
while retries <= max_retries:
|
36 |
try:
|
37 |
-
model = genai.GenerativeModel(
|
38 |
|
39 |
system_prompt = f"""You are a translation engine.
|
40 |
Translate the following text accurately to {target_lang}.
|
@@ -141,7 +143,7 @@ def translate_text(text_dict, source_lang='English', target_lang="Vietnamese", m
|
|
141 |
retry_count = 0
|
142 |
while retry_count < max_retries:
|
143 |
try:
|
144 |
-
model = genai.GenerativeModel(
|
145 |
full_prompt = f"{system_prompt.strip()}\n\n{user_prompt.strip()}"
|
146 |
|
147 |
response = model.generate_content(
|
|
|
7 |
import time
|
8 |
from google.api_core.exceptions import ResourceExhausted
|
9 |
import re
|
10 |
+
from dotenv import load_dotenv
|
11 |
+
load_dotenv() # Load environment variables from .env file
|
12 |
|
13 |
+
genai.configure(os.getenv("GEMINI_API_KEY")) # Configure the Gemini API key
|
14 |
|
15 |
|
16 |
def unzip_office_file(pptx_file: io.BytesIO):
|
|
|
36 |
retries = 0
|
37 |
while retries <= max_retries:
|
38 |
try:
|
39 |
+
model = genai.GenerativeModel(os.getenv("MODEL_VERSION")) # hoặc 'gemini-1.5-flash'
|
40 |
|
41 |
system_prompt = f"""You are a translation engine.
|
42 |
Translate the following text accurately to {target_lang}.
|
|
|
143 |
retry_count = 0
|
144 |
while retry_count < max_retries:
|
145 |
try:
|
146 |
+
model = genai.GenerativeModel(os.getenv("MODEL_VERSION"))
|
147 |
full_prompt = f"{system_prompt.strip()}\n\n{user_prompt.strip()}"
|
148 |
|
149 |
response = model.generate_content(
|
word/word_helper.py
CHANGED
@@ -36,7 +36,7 @@ def batch_translate(texts, source_lang = 'English', target_lang="Vietnamese"):
|
|
36 |
json_data = json.dumps({i: t for i, t in enumerate(texts)})
|
37 |
user_prompt = f"Target language: {target_lang}. JSON file: {json_data}"
|
38 |
|
39 |
-
model = genai.GenerativeModel(
|
40 |
response = model.generate_content(contents = system_prompt.strip() + "\n" + user_prompt.strip(), generation_config={
|
41 |
'temperature': 0.3, # Adjust temperature for desired creativity
|
42 |
'top_p': 1,
|
|
|
36 |
json_data = json.dumps({i: t for i, t in enumerate(texts)})
|
37 |
user_prompt = f"Target language: {target_lang}. JSON file: {json_data}"
|
38 |
|
39 |
+
model = genai.GenerativeModel(os.getenv("MODEL_VERSION"))
|
40 |
response = model.generate_content(contents = system_prompt.strip() + "\n" + user_prompt.strip(), generation_config={
|
41 |
'temperature': 0.3, # Adjust temperature for desired creativity
|
42 |
'top_p': 1,
|