Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
//import gradio as gr
|
3 |
+
import google.generativeai as genai
|
4 |
+
|
5 |
+
# Configure API key for Gemini
|
6 |
+
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", None)
|
7 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
8 |
+
|
9 |
+
# Create the model and chat session once
|
10 |
+
generation_config = {
|
11 |
+
"temperature": 1,
|
12 |
+
"top_p": 0.95,
|
13 |
+
"top_k": 64,
|
14 |
+
"max_output_tokens": 8192,
|
15 |
+
"response_mime_type": "text/plain",
|
16 |
+
}
|
17 |
+
|
18 |
+
model = genai.GenerativeModel(
|
19 |
+
model_name="gemini-1.5-flash",
|
20 |
+
generation_config=generation_config,
|
21 |
+
system_instruction="give the response in a friendly tone",
|
22 |
+
)
|
23 |
+
|
24 |
+
chat_session = model.start_chat(
|
25 |
+
history=[]
|
26 |
+
)
|
27 |
+
|
28 |
+
input = input()
|
29 |
+
|
30 |
+
def chat(input):
|
31 |
+
response = chat_session.send_message(input)
|
32 |
+
return response.text
|
33 |
+
|
34 |
+
# Create Gradio interface
|
35 |
+
|
36 |
+
#gr.Textbox(placeholder="Let Chat")
|
37 |
+
#outputs = chat(inputs)
|
38 |
+
#gr.Textbox()
|
39 |
+
#demo = gr.Interface(fn=chat, inputs=inputs, outputs=outputs)
|
40 |
+
|
41 |
+
# Launch the Gradio interface
|
42 |
+
#if __name__ == "__main__":
|
43 |
+
# demo.launch()
|