Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load Hugging Face's conversational model (DialoGPT in this case) | |
| generator = pipeline("conversational", model="microsoft/DialoGPT-medium") | |
| # Define a function that will interact with the model | |
| def chatbot_response(user_input, chat_history): | |
| # Create response by sending the user input and previous history to the model | |
| response = generator(user_input, pad_token_id=50256) | |
| chat_history.append((user_input, response[0]['generated_text'])) | |
| # Return the updated chat history for displaying the conversation | |
| return chat_history, chat_history | |
| # Gradio interface setup | |
| def create_gradio_interface(): | |
| # Create a chat-based interface using Gradio | |
| interface = gr.Interface( | |
| fn=chatbot_response, | |
| inputs=[gr.Textbox(label="Ask about food customization...", placeholder="Type your message...", lines=1), | |
| gr.State()], | |
| outputs=[gr.Chatbot(), gr.State()], | |
| title="Food Customization Assistant", | |
| description="Talk to the bot and customize your food preferences. Ask about recipes, categories, or ingredients.", | |
| theme="compact" # Custom theme | |
| ) | |
| return interface | |
| if __name__ == "__main__": | |
| interface = create_gradio_interface() | |
| interface.launch() | |