File size: 1,061 Bytes
ab86870 7fb7b85 ae67607 ab86870 7fb7b85 1694eaa ab86870 7fb7b85 ab86870 8937d91 7fb7b85 ab86870 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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()
|