# app.py from transformers import pipeline import gradio as gr # Load the text2text generation pipeline pipe = pipeline("text2text-generation", model="google/flan-t5-base") # Initialize conversation history conversation_history = "" def converse(user_message): global conversation_history # Append the user's message to the conversation history conversation_history += f"User: {user_message}\n" # Generate response response = pipe(conversation_history, max_length=200)[0]['generated_text'] # Append the model's response conversation_history += f"Bot: {response}\n" return response # Gradio UI iface = gr.Interface( fn=converse, inputs=gr.Textbox(lines=2, placeholder="Enter your message...", label="Your Message"), outputs=gr.Textbox(label="Bot Response"), title="Chat with FLAN-T5", description="A simple conversational app using FLAN-T5 and Gradio" ) # Launch for Hugging Face Spaces if __name__ == "__main__": iface.launch()