File size: 1,766 Bytes
5a8b4a7
91849c3
 
5a8b4a7
4ab4257
5a8b4a7
 
 
 
 
 
 
 
 
 
 
4ab4257
5a8b4a7
 
4ab4257
5a8b4a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52a1c89
5a8b4a7
 
 
 
4ab4257
 
5a8b4a7
 
 
 
 
4ab4257
5a8b4a7
 
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
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()