import google.generativeai as genai import os import time import csv import subprocess import matplotlib.pyplot as plt import random import matplotlib.font_manager as fm #15 per minute = 60/15=4 seconds print(os.environ["GEMINI_API_KEY"]) time.sleep(4) #nano ~/.bashrc #export GEMINI_API_KEY= genai.configure(api_key=os.environ["GEMINI_API_KEY"]) model = genai.GenerativeModel('gemini-1.5-flash') model=genai.GenerativeModel( model_name="gemini-1.5-flash", system_instruction="""You are an amazing teacher of the Chinese language. Your students are English. I will provide you the Chinese phrase and you will provide a breakdown in English so one can understand the grammar and meaning of the sentence and words. However, you will do so so that I can translate it using espeakng later. So chinese parts will be marked with [zh] and end with [/zh]. Don't add extra conversation stuff like you are talking to me. Always provide the english translation at the beginning. Do not use asterisk * or - anywhere. Your output will be used with espeak ng to generate a podcast clip. Always enclose any chinese words with [zh]chinese characters[/zh] """) with open('cmn.txt') as f: data = list(csv.reader(f, delimiter='\t')) for i in range(500): try : time.sleep(4) # Select a random row row = random.choice(data) english, other_lang, attribution = row response = model.generate_content(other_lang) print(response.text) # Save the response to a file with open(f'chinese_{i+1}.txt', 'w') as file: str = response.text file.write('[zh]' + other_lang + '[/zh]. ' + str) except: time.sleep(10) print('error') # Retrieve and print file contents in sequence #for i in range(500): # with open(f'output_{i+1}.txt', 'r') as file: # content = file.read() # print(content)