Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,23 +10,23 @@ def load_instruction(persona):
|
|
10 |
except FileNotFoundError:
|
11 |
return ""
|
12 |
|
13 |
-
# Call Cohere R+ model via API
|
14 |
def call_cohere_api(system_instruction, user_prompt):
|
15 |
-
# Replace this with your actual API call to Cohere R+
|
16 |
headers = {
|
17 |
"Authorization": f"Bearer {os.getenv('COHERE_API_KEY')}",
|
18 |
"Content-Type": "application/json"
|
19 |
}
|
20 |
payload = {
|
21 |
"model": "command-r-plus",
|
22 |
-
"
|
|
|
23 |
"max_tokens": 300
|
24 |
}
|
25 |
response = requests.post("https://api.cohere.ai/v1/chat", headers=headers, json=payload)
|
26 |
if response.status_code == 200:
|
27 |
return response.json().get("text", "No response")
|
28 |
else:
|
29 |
-
return f"Error: {response.status_code}"
|
30 |
|
31 |
# Wrapper for dual assistant responses
|
32 |
def ask_forest_oracle(persona1, persona2, prompt):
|
@@ -46,7 +46,7 @@ with gr.Blocks() as demo:
|
|
46 |
persona1 = gr.Dropdown(personas, label="Choose First Persona", value="Tree")
|
47 |
persona2 = gr.Dropdown(personas, label="Choose Second Persona", value="Crow")
|
48 |
|
49 |
-
user_input = gr.Textbox(label="Your Question to the
|
50 |
|
51 |
with gr.Row():
|
52 |
output1 = gr.Textbox(label="Response from Persona 1")
|
|
|
10 |
except FileNotFoundError:
|
11 |
return ""
|
12 |
|
13 |
+
# Call Cohere R+ model via API
|
14 |
def call_cohere_api(system_instruction, user_prompt):
|
|
|
15 |
headers = {
|
16 |
"Authorization": f"Bearer {os.getenv('COHERE_API_KEY')}",
|
17 |
"Content-Type": "application/json"
|
18 |
}
|
19 |
payload = {
|
20 |
"model": "command-r-plus",
|
21 |
+
"message": user_prompt,
|
22 |
+
"preamble": system_instruction,
|
23 |
"max_tokens": 300
|
24 |
}
|
25 |
response = requests.post("https://api.cohere.ai/v1/chat", headers=headers, json=payload)
|
26 |
if response.status_code == 200:
|
27 |
return response.json().get("text", "No response")
|
28 |
else:
|
29 |
+
return f"Error: {response.status_code} - {response.text}"
|
30 |
|
31 |
# Wrapper for dual assistant responses
|
32 |
def ask_forest_oracle(persona1, persona2, prompt):
|
|
|
46 |
persona1 = gr.Dropdown(personas, label="Choose First Persona", value="Tree")
|
47 |
persona2 = gr.Dropdown(personas, label="Choose Second Persona", value="Crow")
|
48 |
|
49 |
+
user_input = gr.Textbox(label="Your Question to the them", placeholder="e.g., What do you think of humans?", lines=2)
|
50 |
|
51 |
with gr.Row():
|
52 |
output1 = gr.Textbox(label="Response from Persona 1")
|