File size: 1,589 Bytes
28d86ed
 
aeea3ef
28d86ed
 
 
 
aeea3ef
28d86ed
79a1ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from google import genai
from google.genai import types
from process.sys_prompt import GENERAL_PROMPT, NEWS_PROMPT, PHILO_PROMPT


NARRATIVE_PROMPT = ""
POEM_PROMPT = ""


def get_interpretation(
    genre: str, api_key: str, text: str, learn_language: str, prof_language: str
) -> str:
    if not api_key:
        return "Error: Gemini API Key not found."
    if not text:
        return "Error: text not found."

    try:
        client = genai.Client(api_key=api_key)
    except Exception as e:
        return f"ERROR: {str(e)}"

    lang_map = {
        "AR": "Arabic",
        "DE": "German",
        "ES": "Spanish",
        "EN": "English",
        "FR": "French",
        "IT": "Italian",
        "JA": "Japanese",
        "RU": "Russian",
        "ZH": "Chinese",
    }
    learn_lang = lang_map.get(learn_language.upper(), "English")
    prof_lang = lang_map.get(prof_language.upper(), "English")
    genres = {
        "general": GENERAL_PROMPT,
        "news": NEWS_PROMPT,
        "narrative": NARRATIVE_PROMPT,
        "poem": POEM_PROMPT,
        "philosophy": PHILO_PROMPT,
    }
    if genre.lower() in ["general", "news", "philosophy"]:
        sys_prompt = (
            genres[genre.lower()]
            .replace("[LEARN_LANGUAGE]", learn_lang)
            .replace("[PROF_LANGUAGE]", prof_lang)
        )

    response = client.models.generate_content(
        model="gemini-2.5-pro",
        config=types.GenerateContentConfig(
            system_instruction=sys_prompt,
            temperature=0.3,
        ),
        contents=[text],
    )
    return response.text