import gradio as gr from transformers import pipeline # Load the model model = pipeline("text-generation", model="rish13/polymers") def generate_response(prompt): # Generate text from the model response = model(prompt, max_length=150, num_return_sequences=1) generated_text = response[0]['generated_text'] # Find the position of the first end-of-sentence punctuation end_punctuation = ['.', '!', '?'] end_position = min((generated_text.find(punct) for punct in end_punctuation if punct in generated_text), default=-1) if end_position != -1: # Include the punctuation in the response generated_text = generated_text[:end_position + 1] return generated_text # Define the Gradio interface interface = gr.Interface( fn=generate_response, inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt"), outputs="text", title="Polymer Knowledge Model", description="A model fine-tuned for generating text related to polymers." ) # Launch the interface interface.launch()