File size: 1,275 Bytes
f3dd5d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01dc73d
 
 
 
f3dd5d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from google import genai
from google.genai import types
from process.sys_prompt import GENERAL_PROMPT, NEWS_PROMPT


NARRATIVE_PROMPT = ""
POEM_PROMPT = ""
PHILO_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 ={"DE": "German", "EN": "English", "FR": "French", "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"]:
		sys_prompt = genres[genre.lower()].replace("[LEARN_LANGUAGE]", learn_lang).replace("[PROF_LANGUAGE]", prof_lang)

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