Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import gradio as grimport timedef print_like_dislike(x: gr.LikeData):print(x.index, x.value, x.liked)def respond(message, history):if not message:return historyuser_text = message.get("text", "") if isinstance(message, dict) else messagefiles = message.get("files", []) if isinstance(message, dict) else []response = f"""**Your Question**: {user_text}**1. Understanding Your Need**This is a project management task requiring an ethical, professional-grade prompt.**2. CLEAR + ROLE + SCARF Framework**β’ **Role** β Senior PMI-certified Project Managerβ’ **Context** β MSc assignment with academic integrity rulesβ’ **Learning Goal** β Build a prompt you can defend and citeβ’ **Expected Output** β Ready-to-copy with bias & autonomy checksβ’ **Audience** β Professor + future employerβ’ **SCARF Guardrails** β You keep final control (Autonomy, Fairness, Certainty)**3. Your Final Prompt**(Here is your perfect, copy-paste-ready prompt β built with ethics first)**4. Critical Thinking Check**Answer aloud before using:1. Can I defend every word as my own judgment?2. Did I check for bias?3. Will I cite this assistance?4. Am I still the Project Manager?**5.** Ready when you are β ask again to refine!"""if files:response += f"\n\n**Files received**: {len(files)} file(s) attached."# Add user message to historyhistory.append({"role": "user", "content": user_text or "(file only)"})history.append({"role": "assistant", "content": ""})# Streaming responsefor char in response:history[-1]["content"] += chartime.sleep(0.015)yield historywith gr.Blocks(title="Ethical Student Project Bot") as demo:gr.Markdown("# Ethical Project Management Chatbot for Students\n""Helps you create defensible, bias-checked prompts with PMI/SCARF ethics.")chatbot = gr.Chatbot(height=600, like_user_message=True)msg = gr.MultimodalTextbox(placeholder="Ask about your assignment, upload files, or record audio...",file_count="multiple",file_types=[".pdf", ".docx", ".jpg", ".png", ".mp3", ".mp4"],sources=["upload", "microphone"],show_label=False,)gr.Examples(examples=[["How should I structure a risk register for my MSc dissertation?"],["Help me write an ethical prompt for generating a Gantt chart"],],inputs=msg,)msg.submit(respond, [msg, chatbot], chatbot).then(lambda: gr.MultimodalTextbox(value=None, interactive=True), None, msg)chatbot.like(print_like_dislike)demo.launch()1234from gradio.sketch.run import createdemo = create("test.py", "test.py.json")demo.launch()
app.py+2-74