Spaces:
Sleeping
Sleeping
Initial commit :tada:
Browse files- .gitignore +2 -0
- README.md +2 -2
- app.py +56 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.idea/
|
2 |
+
venv/
|
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
+
title: Chat-with-Gemini
|
3 |
+
emoji: 💬
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Tuple
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import google.generativeai as genai
|
5 |
+
|
6 |
+
|
7 |
+
def predict(google_key: str, text_prompt: str, chatbot: List[Tuple[str, str]]):
|
8 |
+
if not google_key:
|
9 |
+
raise ValueError(
|
10 |
+
"GOOGLE_API_KEY is not set. "
|
11 |
+
"Please follow the instructions in the README to set it up.")
|
12 |
+
|
13 |
+
genai.configure(api_key=google_key)
|
14 |
+
model = genai.GenerativeModel('models/gemini-pro')
|
15 |
+
response = model.generate_content(text_prompt, stream=True)
|
16 |
+
response.resolve()
|
17 |
+
chatbot.append((text_prompt, response.text))
|
18 |
+
return "", chatbot
|
19 |
+
|
20 |
+
|
21 |
+
google_key_component = gr.Textbox(
|
22 |
+
label="GOOGLE API KEY",
|
23 |
+
value="",
|
24 |
+
type="password",
|
25 |
+
placeholder="...",
|
26 |
+
info="You have to provide your own GPT4 keys for this app to function properly",
|
27 |
+
)
|
28 |
+
|
29 |
+
chatbot_component = gr.Chatbot(label='Gemini')
|
30 |
+
text_prompt_component = gr.Textbox(
|
31 |
+
placeholder="Hi there!",
|
32 |
+
label="Type an input and press Enter"
|
33 |
+
)
|
34 |
+
run_button_component = gr.Button()
|
35 |
+
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
with gr.Column():
|
38 |
+
google_key_component.render()
|
39 |
+
with gr.Row():
|
40 |
+
chatbot_component.render()
|
41 |
+
text_prompt_component.render()
|
42 |
+
run_button_component.render()
|
43 |
+
|
44 |
+
run_button_component.click(
|
45 |
+
fn=predict,
|
46 |
+
inputs=[google_key_component, text_prompt_component, chatbot_component],
|
47 |
+
outputs=[text_prompt_component, chatbot_component],
|
48 |
+
)
|
49 |
+
|
50 |
+
text_prompt_component.submit(
|
51 |
+
fn=predict,
|
52 |
+
inputs=[google_key_component, text_prompt_component, chatbot_component],
|
53 |
+
outputs=[text_prompt_component, chatbot_component],
|
54 |
+
)
|
55 |
+
|
56 |
+
demo.queue(max_size=99).launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
google-generativeai
|
2 |
+
gradio
|