JeCabrera commited on
Commit
373cf9a
verified
1 Parent(s): c3909f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -48
app.py CHANGED
@@ -1,53 +1,14 @@
1
  import gradio as gr
2
  import gemini_gradio
3
- import google.generativeai as genai
4
- import os
5
- from dotenv import load_dotenv # Aseg煤rate de instalar dotenv si no lo tienes: pip install python-dotenv
6
 
7
- # Cargar las variables de entorno desde el archivo .env
8
- load_dotenv()
9
-
10
- # Verifica la versi贸n de genai
11
- print("google-generativeai:", genai.__version__)
12
-
13
- # Obtener la clave de la API de las variables de entorno
14
- GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
15
-
16
- # Verificar que la clave de la API est茅 configurada
17
- if not GOOGLE_API_KEY:
18
- raise ValueError("GOOGLE_API_KEY is not set in environment variables.")
19
-
20
- # Configuraci贸n del modelo Gemini
21
- generation_config = {
22
- "temperature": 1,
23
- "top_p": 0.95,
24
- "top_k": 40,
25
- "max_output_tokens": 8192,
26
- "response_mime_type": "text/plain",
27
- }
28
-
29
- # Configuraci贸n del modelo en gemini_gradio
30
- def configure_model():
31
- genai.configure(api_key=GOOGLE_API_KEY) # Configura la API Key
32
- model = genai.GenerativeModel(
33
- model_name="gemini-1.5-flash",
34
- generation_config=generation_config
35
- )
36
- return model
37
-
38
- # Funci贸n que genera la respuesta usando el modelo configurado
39
- def generate_response(input_text):
40
- model = configure_model() # Cargar el modelo con los par谩metros configurados
41
- response = model.generate(input_text) # Generar la respuesta
42
- return response.text # Ajusta seg煤n la estructura de la respuesta del modelo
43
-
44
- # Integraci贸n con la interfaz Gradio
45
- with gr.Blocks() as demo:
46
- gr.Markdown("**Gemini Model with Custom Parameters**")
47
-
48
- input_text = gr.Textbox(label="Enter Text", placeholder="Type here...")
49
- output_text = gr.Textbox(label="Generated Response")
50
 
51
- input_text.submit(generate_response, inputs=input_text, outputs=output_text)
 
 
 
 
 
52
 
53
- demo.launch()
 
1
  import gradio as gr
2
  import gemini_gradio
 
 
 
3
 
4
+ with gr.Blocks(fill_height=True) as demo:
5
+ gr.Markdown("**Note:** You need to use a SambaNova API key from [SambaNova Cloud](https://cloud.sambanova.ai/).")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ gemini_interface = gr.load(
8
+ name="gemini-1.5-flash", # Se establece el modelo por defecto
9
+ src=gemini_gradio.registry,
10
+ fill_height=True,
11
+ chatbot=gr.Chatbot(type="messages")
12
+ )
13
 
14
+ demo.launch(ssr_mode=False)