Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -58,7 +58,7 @@ counternarratives = load_counternarratives()
|
|
58 |
# Generate Random Myth or Fact and trigger persona response
|
59 |
def get_random_myth_or_fact():
|
60 |
if counternarratives.empty:
|
61 |
-
return "No myths or facts available.", "
|
62 |
|
63 |
# π Randomly select a row from the dataframe
|
64 |
row = counternarratives.sample(1).iloc[0]
|
@@ -76,55 +76,33 @@ def get_random_myth_or_fact():
|
|
76 |
else:
|
77 |
fact_check_response = f"β
**FACT**\n\nIndeed, {row['fact']}"
|
78 |
|
79 |
-
# Return the myth/fact,
|
80 |
-
return myth_or_fact, persona, "Fact-Checker
|
81 |
|
82 |
# Dynamically load persona names from instructions folder
|
83 |
personas = [os.path.splitext(f)[0].capitalize() for f in os.listdir("instructions") if f.endswith(".txt")]
|
84 |
|
85 |
# Gradio Interface
|
86 |
with gr.Blocks() as demo:
|
87 |
-
# Header with Image
|
88 |
with gr.Row():
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
gr.Markdown("""
|
93 |
-
# π² **Wild Voices**
|
94 |
-
*Listening to the More-than-Human World*
|
95 |
-
Ask questions to rivers, trees, owls, and more. Generate myths and facts, and let nature's wisdom respond.
|
96 |
-
""")
|
97 |
-
|
98 |
-
# Persona Selection
|
99 |
with gr.Row():
|
100 |
persona1 = gr.Dropdown(personas, label="Choose First Persona", value="Tree")
|
101 |
-
persona2 = gr.Dropdown(personas
|
102 |
|
103 |
-
# Question and buttons
|
104 |
with gr.Row():
|
105 |
user_input = gr.Textbox(label="π± Your Question", placeholder="e.g., What do you think of humans?", lines=2)
|
106 |
random_button = gr.Button("π² Generate Random Question")
|
107 |
myth_fact_button = gr.Button("π Generate Random Myth/Fact")
|
108 |
|
109 |
-
# Submit button
|
110 |
with gr.Row():
|
111 |
ask_button = gr.Button("π Submit Question")
|
112 |
|
113 |
-
# Response display (side by side)
|
114 |
with gr.Row():
|
115 |
-
output1 = gr.Textbox(label="
|
116 |
-
output2 = gr.Textbox(label="
|
117 |
-
|
118 |
-
# Update labels when dropdown changes
|
119 |
-
def update_labels(p1, p2):
|
120 |
-
label1 = f"{p1} Responds"
|
121 |
-
label2 = f"{p2} Responds"
|
122 |
-
output1.label = label1
|
123 |
-
output2.label = label2
|
124 |
-
return label1, label2
|
125 |
-
|
126 |
-
persona1.change(fn=update_labels, inputs=[persona1, persona2], outputs=[output1, output2])
|
127 |
-
persona2.change(fn=update_labels, inputs=[persona1, persona2], outputs=[output1, output2])
|
128 |
|
129 |
# Button events
|
130 |
random_button.click(fn=get_random_question, inputs=[], outputs=[user_input])
|
@@ -137,16 +115,9 @@ with gr.Blocks() as demo:
|
|
137 |
)
|
138 |
|
139 |
# Ask button for normal questions
|
140 |
-
def ask_with_context(p1, p2, q):
|
141 |
-
res1 = call_cohere_api(load_instruction(p1), q)
|
142 |
-
if p2 == "Fact-Checker π§ ":
|
143 |
-
res2 = f"I am here to verify myths and facts. Ask me anything related to {p1}."
|
144 |
-
else:
|
145 |
-
res2 = call_cohere_api(load_instruction(p2), q)
|
146 |
-
return res1, res2
|
147 |
-
|
148 |
ask_button.click(
|
149 |
-
fn=
|
|
|
150 |
inputs=[persona1, persona2, user_input],
|
151 |
outputs=[output1, output2]
|
152 |
)
|
|
|
58 |
# Generate Random Myth or Fact and trigger persona response
|
59 |
def get_random_myth_or_fact():
|
60 |
if counternarratives.empty:
|
61 |
+
return "No myths or facts available.", "Fact-Checker", "", "", ""
|
62 |
|
63 |
# π Randomly select a row from the dataframe
|
64 |
row = counternarratives.sample(1).iloc[0]
|
|
|
76 |
else:
|
77 |
fact_check_response = f"β
**FACT**\n\nIndeed, {row['fact']}"
|
78 |
|
79 |
+
# Return the myth/fact, update the personas, and fill the responses
|
80 |
+
return myth_or_fact, persona, "Fact-Checker", persona_response, fact_check_response
|
81 |
|
82 |
# Dynamically load persona names from instructions folder
|
83 |
personas = [os.path.splitext(f)[0].capitalize() for f in os.listdir("instructions") if f.endswith(".txt")]
|
84 |
|
85 |
# Gradio Interface
|
86 |
with gr.Blocks() as demo:
|
|
|
87 |
with gr.Row():
|
88 |
+
gr.Markdown("# π² **Wild Voices** β *Listening to the More-than-Human World*")
|
89 |
+
gr.Markdown("Ask questions to rivers, trees, owls, and more. Generate myths and facts, and let nature's wisdom respond.")
|
90 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
with gr.Row():
|
92 |
persona1 = gr.Dropdown(personas, label="Choose First Persona", value="Tree")
|
93 |
+
persona2 = gr.Dropdown(personas, label="Choose Second Persona", value="Crow")
|
94 |
|
|
|
95 |
with gr.Row():
|
96 |
user_input = gr.Textbox(label="π± Your Question", placeholder="e.g., What do you think of humans?", lines=2)
|
97 |
random_button = gr.Button("π² Generate Random Question")
|
98 |
myth_fact_button = gr.Button("π Generate Random Myth/Fact")
|
99 |
|
|
|
100 |
with gr.Row():
|
101 |
ask_button = gr.Button("π Submit Question")
|
102 |
|
|
|
103 |
with gr.Row():
|
104 |
+
output1 = gr.Textbox(label=f"{persona1.value} Responds")
|
105 |
+
output2 = gr.Textbox(label="Fact-Checker Responds")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
# Button events
|
108 |
random_button.click(fn=get_random_question, inputs=[], outputs=[user_input])
|
|
|
115 |
)
|
116 |
|
117 |
# Ask button for normal questions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
ask_button.click(
|
119 |
+
fn=lambda p1, p2, q: (call_cohere_api(load_instruction(p1), q),
|
120 |
+
call_cohere_api(load_instruction(p2), q)),
|
121 |
inputs=[persona1, persona2, user_input],
|
122 |
outputs=[output1, output2]
|
123 |
)
|