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,8 +76,8 @@ 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", 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")]
|
@@ -87,7 +87,7 @@ with gr.Blocks() as demo:
|
|
87 |
# Header with Image
|
88 |
with gr.Row():
|
89 |
with gr.Column(scale=0.15):
|
90 |
-
gr.Image(value="data/
|
91 |
with gr.Column():
|
92 |
gr.Markdown("""
|
93 |
# π² **Wild Voices**
|
@@ -98,7 +98,7 @@ with gr.Blocks() as demo:
|
|
98 |
# Persona Selection
|
99 |
with gr.Row():
|
100 |
persona1 = gr.Dropdown(personas, label="Choose First Persona", value="Tree")
|
101 |
-
persona2 = gr.Dropdown(personas, label="Choose Second Persona", value="Crow")
|
102 |
|
103 |
# Question and buttons
|
104 |
with gr.Row():
|
@@ -110,9 +110,10 @@ with gr.Blocks() as demo:
|
|
110 |
with gr.Row():
|
111 |
ask_button = gr.Button("π Submit Question")
|
112 |
|
113 |
-
# Response display
|
114 |
-
|
115 |
-
|
|
|
116 |
|
117 |
# Update labels when dropdown changes
|
118 |
def update_labels(p1, p2):
|
@@ -132,9 +133,16 @@ with gr.Blocks() as demo:
|
|
132 |
)
|
133 |
|
134 |
# Ask button for normal questions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
ask_button.click(
|
136 |
-
fn=
|
137 |
-
call_cohere_api(load_instruction(p2), q)),
|
138 |
inputs=[persona1, persona2, user_input],
|
139 |
outputs=[output1, output2]
|
140 |
)
|
|
|
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.", "Tree", "Crow", "Error: No Data Found.", "Error: No Data Found."
|
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, set 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")]
|
|
|
87 |
# Header with Image
|
88 |
with gr.Row():
|
89 |
with gr.Column(scale=0.15):
|
90 |
+
gr.Image(value="data/WildVoices.png", label="Wild Voices", show_label=False)
|
91 |
with gr.Column():
|
92 |
gr.Markdown("""
|
93 |
# π² **Wild Voices**
|
|
|
98 |
# Persona Selection
|
99 |
with gr.Row():
|
100 |
persona1 = gr.Dropdown(personas, label="Choose First Persona", value="Tree")
|
101 |
+
persona2 = gr.Dropdown(personas + ["Fact-Checker π§ "], label="Choose Second Persona", value="Crow")
|
102 |
|
103 |
# Question and buttons
|
104 |
with gr.Row():
|
|
|
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=f"{persona1.value} Responds")
|
116 |
+
output2 = gr.Textbox(label=f"{persona2.value} Responds")
|
117 |
|
118 |
# Update labels when dropdown changes
|
119 |
def update_labels(p1, p2):
|
|
|
133 |
)
|
134 |
|
135 |
# Ask button for normal questions
|
136 |
+
def ask_with_context(p1, p2, q):
|
137 |
+
res1 = call_cohere_api(load_instruction(p1), q)
|
138 |
+
if p2 == "Fact-Checker π§ ":
|
139 |
+
res2 = "I am here to verify facts and dispel myths."
|
140 |
+
else:
|
141 |
+
res2 = call_cohere_api(load_instruction(p2), q)
|
142 |
+
return res1, res2
|
143 |
+
|
144 |
ask_button.click(
|
145 |
+
fn=ask_with_context,
|
|
|
146 |
inputs=[persona1, persona2, user_input],
|
147 |
outputs=[output1, output2]
|
148 |
)
|