Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,43 @@
|
|
1 |
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
-
|
5 |
import google.generativeai as genai
|
6 |
|
7 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", None)
|
8 |
genai.configure(api_key=GEMINI_API_KEY)
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
def model(input):
|
10 |
+
|
11 |
+
# Create the model
|
12 |
+
generation_config = {
|
13 |
+
"temperature": 1,
|
14 |
+
"top_p": 0.95,
|
15 |
+
"top_k": 64,
|
16 |
+
"max_output_tokens": 8192,
|
17 |
+
"response_mime_type": "text/plain",
|
18 |
+
}
|
19 |
+
|
20 |
+
model = genai.GenerativeModel(
|
21 |
+
model_name="gemini-1.5-flash",
|
22 |
+
generation_config=generation_config,
|
23 |
+
# safety_settings = Adjust safety settings
|
24 |
+
# See https://ai.google.dev/gemini-api/docs/safety-settings
|
25 |
+
system_instruction="give the response in friendly tone",
|
26 |
+
)
|
27 |
+
|
28 |
+
chat_session = model.start_chat(
|
29 |
+
history=[
|
30 |
+
|
31 |
+
]
|
32 |
+
)
|
33 |
+
|
34 |
+
response = chat_session.send_message(input)
|
35 |
+
|
36 |
+
return response.text
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
demo = gr.Interface(fn=model, inputs="textbox", outputs="textbox")
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
demo.launch()
|