Spaces:
Nymbo
/
Runtime error

SkalskiP commited on
Commit
7916190
1 Parent(s): eeb8511

`app.py` updates

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -10,7 +10,9 @@ DUPLICATE = """
10
  <a href="https://huggingface.co/spaces/SkalskiP/ChatGemini?duplicate=true">
11
  <img src="https://bit.ly/3gLdBN6" alt="Duplicate Space" style="margin-right: 10px;">
12
  </a>
13
- <span>Duplicate the Space and run securely with your GOOGLE API KEY.</span>
 
 
14
  </div>
15
  """
16
 
@@ -19,6 +21,7 @@ def predict(
19
  google_key: str,
20
  text_prompt: str,
21
  image_prompt: Optional[Image.Image],
 
22
  chatbot: List[Tuple[str, str]]
23
  ) -> Tuple[str, List[Tuple[str, str]]]:
24
  if not google_key:
@@ -27,14 +30,21 @@ def predict(
27
  "Please follow the instructions in the README to set it up.")
28
 
29
  genai.configure(api_key=google_key)
 
30
 
31
  if image_prompt is None:
32
  model = genai.GenerativeModel('gemini-pro')
33
- response = model.generate_content(text_prompt, stream=True)
 
 
 
34
  response.resolve()
35
  else:
36
  model = genai.GenerativeModel('gemini-pro-vision')
37
- response = model.generate_content([text_prompt, image_prompt], stream=True)
 
 
 
38
  response.resolve()
39
 
40
  chatbot.append((text_prompt, response.text))
@@ -56,11 +66,19 @@ text_prompt_component = gr.Textbox(
56
  label="Ask me anything and press Enter"
57
  )
58
  run_button_component = gr.Button()
 
 
 
 
 
 
 
59
 
60
  inputs = [
61
  google_key_component,
62
  text_prompt_component,
63
  image_prompt_component,
 
64
  chatbot_component
65
  ]
66
 
@@ -74,6 +92,8 @@ with gr.Blocks() as demo:
74
  chatbot_component.render()
75
  text_prompt_component.render()
76
  run_button_component.render()
 
 
77
 
78
  run_button_component.click(
79
  fn=predict,
 
10
  <a href="https://huggingface.co/spaces/SkalskiP/ChatGemini?duplicate=true">
11
  <img src="https://bit.ly/3gLdBN6" alt="Duplicate Space" style="margin-right: 10px;">
12
  </a>
13
+ <span>Duplicate the Space and run securely with your
14
+ <a href="https://makersuite.google.com/app/apikey">GOOGLE API KEY</a>.
15
+ </span>
16
  </div>
17
  """
18
 
 
21
  google_key: str,
22
  text_prompt: str,
23
  image_prompt: Optional[Image.Image],
24
+ temperature: float,
25
  chatbot: List[Tuple[str, str]]
26
  ) -> Tuple[str, List[Tuple[str, str]]]:
27
  if not google_key:
 
30
  "Please follow the instructions in the README to set it up.")
31
 
32
  genai.configure(api_key=google_key)
33
+ generation_config = genai.types.GenerationConfig(temperature=temperature)
34
 
35
  if image_prompt is None:
36
  model = genai.GenerativeModel('gemini-pro')
37
+ response = model.generate_content(
38
+ text_prompt,
39
+ stream=True,
40
+ generation_config=generation_config)
41
  response.resolve()
42
  else:
43
  model = genai.GenerativeModel('gemini-pro-vision')
44
+ response = model.generate_content(
45
+ [text_prompt, image_prompt],
46
+ stream=True,
47
+ generation_config=generation_config)
48
  response.resolve()
49
 
50
  chatbot.append((text_prompt, response.text))
 
66
  label="Ask me anything and press Enter"
67
  )
68
  run_button_component = gr.Button()
69
+ temperature_component = gr.Slider(
70
+ minimum=0,
71
+ maximum=1.0,
72
+ value=0.5,
73
+ step=0.05,
74
+ label="Temperature",
75
+ info="Controls the randomness of the output.")
76
 
77
  inputs = [
78
  google_key_component,
79
  text_prompt_component,
80
  image_prompt_component,
81
+ temperature_component,
82
  chatbot_component
83
  ]
84
 
 
92
  chatbot_component.render()
93
  text_prompt_component.render()
94
  run_button_component.render()
95
+ with gr.Accordion("Parameters", open=False):
96
+ temperature_component.render()
97
 
98
  run_button_component.click(
99
  fn=predict,