Update app.py
Browse files
app.py
CHANGED
|
@@ -1,76 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
import time
|
| 3 |
-
|
| 4 |
-
def print_like_dislike(x: gr.LikeData):
|
| 5 |
-
print(x.index, x.value, x.liked)
|
| 6 |
-
|
| 7 |
-
def respond(message, history):
|
| 8 |
-
if not message:
|
| 9 |
-
return history
|
| 10 |
-
|
| 11 |
-
user_text = message.get("text", "") if isinstance(message, dict) else message
|
| 12 |
-
files = message.get("files", []) if isinstance(message, dict) else []
|
| 13 |
-
|
| 14 |
-
response = f"""
|
| 15 |
-
**Your Question**: {user_text}
|
| 16 |
-
**1. Understanding Your Need**
|
| 17 |
-
This is a project management task requiring an ethical, professional-grade prompt.
|
| 18 |
-
**2. CLEAR + ROLE + SCARF Framework**
|
| 19 |
-
β’ **Role** β Senior PMI-certified Project Manager
|
| 20 |
-
β’ **Context** β MSc assignment with academic integrity rules
|
| 21 |
-
β’ **Learning Goal** β Build a prompt you can defend and cite
|
| 22 |
-
β’ **Expected Output** β Ready-to-copy with bias & autonomy checks
|
| 23 |
-
β’ **Audience** β Professor + future employer
|
| 24 |
-
β’ **SCARF Guardrails** β You keep final control (Autonomy, Fairness, Certainty)
|
| 25 |
-
**3. Your Final Prompt**
|
| 26 |
-
(Here is your perfect, copy-paste-ready prompt β built with ethics first)
|
| 27 |
-
**4. Critical Thinking Check**
|
| 28 |
-
Answer aloud before using:
|
| 29 |
-
1. Can I defend every word as my own judgment?
|
| 30 |
-
2. Did I check for bias?
|
| 31 |
-
3. Will I cite this assistance?
|
| 32 |
-
4. Am I still the Project Manager?
|
| 33 |
-
**5.** Ready when you are β ask again to refine!"""
|
| 34 |
-
|
| 35 |
-
if files:
|
| 36 |
-
response += f"\n\n**Files received**: {len(files)} file(s) attached."
|
| 37 |
-
|
| 38 |
-
# Add user message to history
|
| 39 |
-
history.append({"role": "user", "content": user_text or "(file only)"})
|
| 40 |
-
history.append({"role": "assistant", "content": ""})
|
| 41 |
-
|
| 42 |
-
# Streaming response
|
| 43 |
-
for char in response:
|
| 44 |
-
history[-1]["content"] += char
|
| 45 |
-
time.sleep(0.015)
|
| 46 |
-
yield history
|
| 47 |
-
|
| 48 |
-
with gr.Blocks(title="Ethical Student Project Bot") as demo:
|
| 49 |
-
gr.Markdown("# Ethical Project Management Chatbot for Students\n"
|
| 50 |
-
"Helps you create defensible, bias-checked prompts with PMI/SCARF ethics.")
|
| 51 |
-
|
| 52 |
-
chatbot = gr.Chatbot(height=600, like_user_message=True)
|
| 53 |
-
|
| 54 |
-
msg = gr.MultimodalTextbox(
|
| 55 |
-
placeholder="Ask about your assignment, upload files, or record audio...",
|
| 56 |
-
file_count="multiple",
|
| 57 |
-
file_types=[".pdf", ".docx", ".jpg", ".png", ".mp3", ".mp4"],
|
| 58 |
-
sources=["upload", "microphone"],
|
| 59 |
-
show_label=False,
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
gr.Examples(
|
| 63 |
-
examples=[
|
| 64 |
-
["How should I structure a risk register for my MSc dissertation?"],
|
| 65 |
-
["Help me write an ethical prompt for generating a Gantt chart"],
|
| 66 |
-
],
|
| 67 |
-
inputs=msg,
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
msg.submit(respond, [msg, chatbot], chatbot).then(
|
| 71 |
-
lambda: gr.MultimodalTextbox(value=None, interactive=True), None, msg
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
chatbot.like(print_like_dislike)
|
| 75 |
|
|
|
|
| 76 |
demo.launch()
|
|
|
|
| 1 |
+
from gradio.sketch.run import create
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
demo = create("test.py", "test.py.json")
|
| 4 |
demo.launch()
|