Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline, Conversation | |
| # Modelo de Hugging Face para conversaci贸n | |
| model_name = "microsoft/DialoGPT-large" | |
| conversation_model = pipeline("conversational", model=model_name) | |
| # Historial de la conversaci贸n, se mantendr谩 dentro del contexto de la aplicaci贸n | |
| conversation = Conversation() | |
| # Funci贸n para procesar la entrada del usuario y generar la respuesta | |
| def chatbot_response(user_input): | |
| # Agregar la respuesta del usuario al historial de la conversaci贸n | |
| conversation.add_user_input(user_input) | |
| # Generar la respuesta del bot | |
| bot_response = conversation_model(user_input, conversation=conversation)["generated_text"] | |
| # Agregar la respuesta del bot al historial de la conversaci贸n | |
| conversation.add_system_output(bot_response) | |
| # Retornar la respuesta del bot para mostrarla en la interfaz | |
| return bot_response | |
| # Ejecuci贸n de la aplicaci贸n | |
| if __name__ == "__main__": | |
| # Interfaz de Gradio para la aplicaci贸n web | |
| iface = gr.Interface( | |
| fn=chatbot_response, | |
| inputs=gr.Textbox(lines=2, placeholder="Escribe tu mensaje aqu铆..."), | |
| outputs=gr.Textbox(lines=2, placeholder="Respuesta del bot..."), | |
| title="Entrevista de Programaci贸n - ChatBot", | |
| theme="compact", | |
| live=True | |
| ) | |
| # Lanzar la interfaz de Gradio | |
| iface.launch() | |