import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer # Load Pre-Trained Model model_name = "mistralai/Mistral-7B-Instruct-v0.1" # Change this to your selected model tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) # Define Chatbot Function def ethical_ai_chat(user_input): inputs = tokenizer(user_input, return_tensors="pt") output = model.generate(**inputs, max_length=200) response = tokenizer.decode(output[0], skip_special_tokens=True) return response # Create Chat Interface chatbot = gr.Interface( fn=ethical_ai_chat, inputs=gr.Textbox(lines=2, placeholder="Ask about AI ethics..."), outputs="text", title="Ethical AI Chatbot", description="A chatbot that helps with ethical dilemmas in AI development." ) # Launch Chatbot chatbot.launch()