import gradio as gr from transformers import pipeline # Load the model model_name = "gpt2" generator = pipeline("text-generation", model=model_name) # Inference function def generate_response(prompt): # Adjust the prompt to guide the model modified_prompt = f"Answer the question directly: {prompt}" response = generator( modified_prompt, max_length=150, # Maintain this to allow for longer responses num_return_sequences=1, temperature=0.7, top_k=50, top_p=0.95 ) return response[0]['generated_text'].strip() # Gradio interface interface = gr.Interface( fn=generate_response, inputs="text", outputs="text", title="Conversational LLM", description="Enter a prompt to generate a relevant and coherent response." ) # Launch the interface interface.launch()