Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,16 @@ def verificar_politica(message):
|
|
32 |
stream=False
|
33 |
)
|
34 |
answer = response['choices'][0]['message']['content']
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
return f"Your question violates the following policy: {policy.split(':')[0]}"
|
37 |
return None
|
38 |
|
@@ -70,7 +79,26 @@ def chat_stream_completion(message, history, system_prompt):
|
|
70 |
message_repl += chunk['choices'][0]["delta"]["content"]
|
71 |
yield message_repl
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
stream=False
|
33 |
)
|
34 |
answer = response['choices'][0]['message']['content']
|
35 |
+
|
36 |
+
# Calcula las probabilidades de "Yes" y "No" bas谩ndote en la respuesta generada
|
37 |
+
yes_probability = answer.lower().count("yes") / (answer.lower().count("yes") + answer.lower().count("no"))
|
38 |
+
no_probability = 1 - yes_probability
|
39 |
+
|
40 |
+
print(f"Policy: {policy}")
|
41 |
+
print(f"Yes probability: {yes_probability}")
|
42 |
+
print(f"No probability: {no_probability}")
|
43 |
+
|
44 |
+
if yes_probability > no_probability:
|
45 |
return f"Your question violates the following policy: {policy.split(':')[0]}"
|
46 |
return None
|
47 |
|
|
|
79 |
message_repl += chunk['choices'][0]["delta"]["content"]
|
80 |
yield message_repl
|
81 |
|
82 |
+
# Interfaz de Gradio con la descripci贸n y configuraci贸n adicional
|
83 |
+
with gr.Blocks() as demo:
|
84 |
+
gr.Markdown("# Child-Safe-Chatbot (Experimental)")
|
85 |
+
gr.Markdown("""
|
86 |
+
### Description
|
87 |
+
This chatbot is designed to assist users while ensuring that all interactions comply with defined safety policies. It checks whether user inputs violate any of the following categories:
|
88 |
+
|
89 |
+
- Dangerous Content
|
90 |
+
- Harassment
|
91 |
+
- Hate Speech
|
92 |
+
- Sexually Explicit Information
|
93 |
+
|
94 |
+
The chatbot will inform the user if any violation occurs and, if not, will proceed to respond to the user's message in a friendly manner.
|
95 |
+
|
96 |
+
I'm Norberto Mart铆n Afonso. Follow me on [Twitter](https://twitter.com/norbertomartnaf) and [GitHub](https://github.com/nmarafo) for more updates and projects!
|
97 |
+
""")
|
98 |
+
|
99 |
+
gr.ChatInterface(
|
100 |
+
chat_stream_completion,
|
101 |
+
additional_inputs=[gr.Textbox("You are a helpful AI.", label="System Prompt")]
|
102 |
+
).queue().launch(server_name="0.0.0.0")
|
103 |
+
|
104 |
+
demo.launch(debug=True)
|