lalashechka commited on
Commit
5a8b4a7
1 Parent(s): 57fe4ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import google.generativeai as genai
2
+
3
+ def flip_text(prompt):
4
+ def init_api_keys():
5
+ try:
6
+
7
+ api_key = 'AIzaSyBYxPTwLyP7D6Hiyydk3olQ1FeXoP78wmc'
8
+ genai.configure(api_key=api_key)
9
+ except Exception as exception:
10
+ print("Error in initializing API keys:", exception)
11
+ raise
12
+
13
+
14
+ def generate_response(prompt: str):
15
+ # Set up the model
16
+ generation_config = {
17
+ "temperature": 0.1,
18
+ "top_p": 1,
19
+ "top_k": 1,
20
+ "max_output_tokens": 2048,
21
+ }
22
+
23
+ model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest", generation_config=generation_config)
24
+
25
+ prompt_parts = [prompt]
26
+
27
+ try:
28
+ response = model.generate_content(prompt_parts)
29
+ print(response.text)
30
+ return response.text
31
+ except Exception as exception:
32
+ print("Error generating response:", exception)
33
+
34
+
35
+
36
+ init_api_keys()
37
+ ans = generate_response(prompt)
38
+ return ans
39
+
40
+
41
+ with gr.Blocks(css=css) as demo:
42
+
43
+ with gr.Tab("Базовые настройки"):
44
+ with gr.Row():
45
+ prompt = gr.Textbox(placeholder="Введите описание...", show_label=True, label='Описание:', lines=3)
46
+
47
+ with gr.Column():
48
+ text_button = gr.Button("Сгенерировать текст", variant='primary', elem_id="generate")
49
+ with gr.Column():
50
+ image_output = gr.Textbox(lines=30, elem_id='image_output')
51
+ text_button.click(flip_text, inputs=[prompt], outputs=image_output, concurrency_limit=48)
52
+
53
+ demo.launch()