File size: 935 Bytes
75e9e3d
 
 
 
2e4a5e8
75e9e3d
 
 
2e4a5e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a2aaa0
 
 
2e4a5e8
cdabf37
 
2e4a5e8
7a2aaa0
2e4a5e8
7a2aaa0
2e4a5e8
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
import os
import gradio as gr
import google.generativeai as genai

# Configure API key for Gemini
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", None)
genai.configure(api_key=GEMINI_API_KEY)

# Create the model and chat session once
generation_config = {
    "temperature": 1,
    "top_p": 0.95,
    "top_k": 64,
    "max_output_tokens": 8192,
    "response_mime_type": "text/plain",
}

model = genai.GenerativeModel(
    model_name="gemini-1.5-flash",
    generation_config=generation_config,
    system_instruction="give the response in a friendly tone",
)

chat_session = model.start_chat(
    history=[]
)

def chat(input):
    response = chat_session.send_message(input)
    return response.text

# Create Gradio interface
inputs = gr.Textbox(placeholder="Let Chat")
outputs = gr.Textbox()
demo = gr.Interface(fn=chat, inputs=inputs, outputs=outputs)

# Launch the Gradio interface
if __name__ == "__main__":
    demo.launch()