Spaces:
Runtime error
Runtime error
artificialguybr
commited on
Commit
•
200c47a
1
Parent(s):
3bb2495
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ def encode_image(image):
|
|
17 |
with open(image_path, "rb") as image_file:
|
18 |
return base64.b64encode(image_file.read()).decode('utf-8')
|
19 |
|
20 |
-
def bot_streaming(message, history, api_key, model, temperature, max_tokens, top_p, top_k, frequency_penalty, presence_penalty, repetition_penalty, stop, min_p, top_a, seed, logit_bias, logprobs, top_logprobs, response_format, tools, tool_choice):
|
21 |
headers = {
|
22 |
"Authorization": f"Bearer {api_key}",
|
23 |
"Content-Type": "application/json"
|
@@ -26,6 +26,9 @@ def bot_streaming(message, history, api_key, model, temperature, max_tokens, top
|
|
26 |
messages = []
|
27 |
images = []
|
28 |
|
|
|
|
|
|
|
29 |
for i, msg in enumerate(history):
|
30 |
if isinstance(msg[0], tuple):
|
31 |
image, text = msg[0]
|
@@ -116,12 +119,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
116 |
2. Choose a model or enter a custom model name/endpoint
|
117 |
3. Start chatting!
|
118 |
|
119 |
-
## 🔧 Settings:
|
120 |
-
- Adjust basic parameters in the "Common Settings" section
|
121 |
-
- Fine-tune options in the "Advanced Settings" section
|
122 |
-
- Access expert-level controls in the "Expert Settings" section
|
123 |
-
- Upload images for multimodal interactions
|
124 |
-
|
125 |
Enjoy your AI-powered conversation!
|
126 |
""")
|
127 |
|
@@ -150,6 +147,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
150 |
value="google/gemini-flash-1.5",
|
151 |
allow_custom_value=True
|
152 |
)
|
|
|
153 |
|
154 |
with gr.Accordion("Common Settings", open=False):
|
155 |
temperature = gr.Slider(minimum=0, maximum=2, value=1, step=0.1, label="Temperature")
|
@@ -178,7 +176,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
178 |
chatbot = gr.ChatInterface(
|
179 |
fn=bot_streaming,
|
180 |
additional_inputs=[
|
181 |
-
api_key, model, temperature, max_tokens, top_p, top_k,
|
182 |
frequency_penalty, presence_penalty, repetition_penalty, stop,
|
183 |
min_p, top_a, seed, logit_bias, logprobs, top_logprobs,
|
184 |
response_format, tools, tool_choice
|
@@ -193,4 +191,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
193 |
fill_height=True,
|
194 |
)
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
demo.launch(debug=True, share=True)
|
|
|
17 |
with open(image_path, "rb") as image_file:
|
18 |
return base64.b64encode(image_file.read()).decode('utf-8')
|
19 |
|
20 |
+
def bot_streaming(message, history, api_key, model, system_prompt, temperature, max_tokens, top_p, top_k, frequency_penalty, presence_penalty, repetition_penalty, stop, min_p, top_a, seed, logit_bias, logprobs, top_logprobs, response_format, tools, tool_choice):
|
21 |
headers = {
|
22 |
"Authorization": f"Bearer {api_key}",
|
23 |
"Content-Type": "application/json"
|
|
|
26 |
messages = []
|
27 |
images = []
|
28 |
|
29 |
+
if system_prompt:
|
30 |
+
messages.append({"role": "system", "content": system_prompt})
|
31 |
+
|
32 |
for i, msg in enumerate(history):
|
33 |
if isinstance(msg[0], tuple):
|
34 |
image, text = msg[0]
|
|
|
119 |
2. Choose a model or enter a custom model name/endpoint
|
120 |
3. Start chatting!
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
Enjoy your AI-powered conversation!
|
123 |
""")
|
124 |
|
|
|
147 |
value="google/gemini-flash-1.5",
|
148 |
allow_custom_value=True
|
149 |
)
|
150 |
+
system_prompt = gr.Textbox(label="System Prompt", placeholder="Enter a system prompt (optional)")
|
151 |
|
152 |
with gr.Accordion("Common Settings", open=False):
|
153 |
temperature = gr.Slider(minimum=0, maximum=2, value=1, step=0.1, label="Temperature")
|
|
|
176 |
chatbot = gr.ChatInterface(
|
177 |
fn=bot_streaming,
|
178 |
additional_inputs=[
|
179 |
+
api_key, model, system_prompt, temperature, max_tokens, top_p, top_k,
|
180 |
frequency_penalty, presence_penalty, repetition_penalty, stop,
|
181 |
min_p, top_a, seed, logit_bias, logprobs, top_logprobs,
|
182 |
response_format, tools, tool_choice
|
|
|
191 |
fill_height=True,
|
192 |
)
|
193 |
|
194 |
+
gr.Markdown("""
|
195 |
+
## 🔧 Settings:
|
196 |
+
- Adjust basic parameters in the "Common Settings" section
|
197 |
+
- Fine-tune options in the "Advanced Settings" section
|
198 |
+
- Access expert-level controls in the "Expert Settings" section
|
199 |
+
- Upload images for multimodal interactions
|
200 |
+
""")
|
201 |
+
|
202 |
demo.launch(debug=True, share=True)
|