Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,39 @@
|
|
1 |
-
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
import google.generativeai as genai
|
5 |
|
|
|
6 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", None)
|
7 |
genai.configure(api_key=GEMINI_API_KEY)
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
history=[
|
30 |
-
|
31 |
-
]
|
32 |
-
)
|
33 |
-
|
34 |
response = chat_session.send_message(input)
|
35 |
-
|
36 |
return response.text
|
37 |
|
38 |
-
|
39 |
-
|
40 |
inputs = gr.Textbox(placeholder="Let Chat")
|
41 |
outputs = gr.Textbox()
|
42 |
-
demo
|
43 |
|
|
|
44 |
if __name__ == "__main__":
|
45 |
-
demo.launch()
|
|
|
|
|
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 |
+
def chat(input):
|
|
|
|
|
|
|
|
|
|
|
29 |
response = chat_session.send_message(input)
|
|
|
30 |
return response.text
|
31 |
|
32 |
+
# Create Gradio interface
|
|
|
33 |
inputs = gr.Textbox(placeholder="Let Chat")
|
34 |
outputs = gr.Textbox()
|
35 |
+
demo = gr.Interface(fn=chat, inputs=inputs, outputs=outputs)
|
36 |
|
37 |
+
# Launch the Gradio interface
|
38 |
if __name__ == "__main__":
|
39 |
+
demo.launch()
|