Spaces:
Runtime error
Runtime error
import google.generativeai as genai | |
import gradio as gr | |
def flip_text(prompt): | |
def init_api_keys(): | |
try: | |
api_key = 'AIzaSyBYxPTwLyP7D6Hiyydk3olQ1FeXoP78wmc' | |
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": 0.1, | |
"top_p": 1, | |
"top_k": 1, | |
"max_output_tokens": 2048, | |
} | |
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.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], outputs=image_output, concurrency_limit=48) | |
demo.launch() |