dtometzki commited on
Commit
91b1942
·
verified ·
1 Parent(s): 1d1ca16

Update app_2.py

Browse files
Files changed (1) hide show
  1. app_2.py +12 -5
app_2.py CHANGED
@@ -6,10 +6,20 @@ from google.genai import types
6
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
7
  MODEL = "gemini-3.1-flash-lite-preview"
8
 
 
 
 
 
 
 
 
9
  def respond(message, history, state):
10
  # history: [{"role": "user"/"assistant", "content": "..."} , ...]
11
  if state is None:
12
- state = {"chat": client.chats.create(model=MODEL), "lock": threading.Lock()}
 
 
 
13
 
14
  history = history or []
15
  text = (message or {}).get("text") or ""
@@ -46,23 +56,20 @@ def respond(message, history, state):
46
  yield history, state
47
 
48
  def clear_msg():
49
- # Clears MultimodalTextbox (Text + Files)
50
  return {"text": "", "files": []}
51
 
52
  with gr.Blocks() as demo:
53
  gr.Markdown("# Gemini Thinking AI")
54
- chatbot = gr.Chatbot(height=600) # messages-format default
55
  msg = gr.MultimodalTextbox(
56
  placeholder="Schreib was oder lade Dateien hoch…",
57
  file_count="multiple",
58
  )
59
  state = gr.State(None)
60
 
61
- # Submit + danach Input leeren
62
  msg.submit(respond, inputs=[msg, chatbot, state], outputs=[chatbot, state]) \
63
  .then(clear_msg, outputs=msg)
64
 
65
- # Clear Button: Chat + State + Input leeren
66
  gr.Button("Clear").click(lambda: ([], None, {"text": "", "files": []}),
67
  outputs=[chatbot, state, msg])
68
 
 
6
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
7
  MODEL = "gemini-3.1-flash-lite-preview"
8
 
9
+ # Tools + Config (einmalig)
10
+ tools = [types.Tool(googleSearch=types.GoogleSearch())]
11
+ generate_content_config = types.GenerateContentConfig(
12
+ thinking_config=types.ThinkingConfig(thinking_level="MINIMAL"),
13
+ tools=tools,
14
+ )
15
+
16
  def respond(message, history, state):
17
  # history: [{"role": "user"/"assistant", "content": "..."} , ...]
18
  if state is None:
19
+ state = {
20
+ "chat": client.chats.create(model=MODEL, config=generate_content_config),
21
+ "lock": threading.Lock(),
22
+ }
23
 
24
  history = history or []
25
  text = (message or {}).get("text") or ""
 
56
  yield history, state
57
 
58
  def clear_msg():
 
59
  return {"text": "", "files": []}
60
 
61
  with gr.Blocks() as demo:
62
  gr.Markdown("# Gemini Thinking AI")
63
+ chatbot = gr.Chatbot(height=600)
64
  msg = gr.MultimodalTextbox(
65
  placeholder="Schreib was oder lade Dateien hoch…",
66
  file_count="multiple",
67
  )
68
  state = gr.State(None)
69
 
 
70
  msg.submit(respond, inputs=[msg, chatbot, state], outputs=[chatbot, state]) \
71
  .then(clear_msg, outputs=msg)
72
 
 
73
  gr.Button("Clear").click(lambda: ([], None, {"text": "", "files": []}),
74
  outputs=[chatbot, state, msg])
75