gemimi-api / app.py
lalashechka's picture
Update app.py
4ab4257 verified
raw
history blame
No virus
1.77 kB
import google.generativeai as genai
import gradio as gr
def flip_text(prompt, api_key):
def init_api_keys():
try:
genai.configure(api_key=api_key)
except Exception as exception:
print("Error in initializing API keys:", exception)
raise
def generate_response(prompt: str):
# Set up the model
generation_config = {
"temperature": 1,
"top_p": 1,
"top_k": 1,
"max_output_tokens": 8192,
}
model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest", generation_config=generation_config)
prompt_parts = [prompt]
try:
response = model.generate_content(prompt_parts)
print(response.text)
return response.text
except Exception as exception:
print("Error generating response:", exception)
init_api_keys()
ans = generate_response(prompt)
return ans
with gr.Blocks() as demo:
with gr.Tab("Базовые настройки"):
with gr.Row():
prompt = gr.Textbox(placeholder="Введите описание...", show_label=True, label='Описание:', lines=3)
with gr.Row():
api_key = gr.Textbox(placeholder="Введите api_key...", show_label=True, label='Описание:', lines=3)
with gr.Column():
text_button = gr.Button("Сгенерировать текст", variant='primary', elem_id="generate")
with gr.Column():
image_output = gr.Textbox(lines=30, elem_id='image_output')
text_button.click(flip_text, inputs=[prompt, api_key], outputs=image_output, concurrency_limit=48)
demo.launch()