File size: 1,206 Bytes
ab86870
 
 
7fb7b85
ae67607
ab86870
7fb7b85
 
 
892e1e5
 
1694eaa
 
 
 
892e1e5
 
 
 
 
1694eaa
892e1e5
1694eaa
 
892e1e5
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
34
35
36
37
38
39
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)
    
    # Get the generated text from the response
    generated_text = response[0]['generated_text']

    # Find the position of the first end-of-sentence punctuation
    end_punctuation = ['.', '!', '?']
    end_position = -1
    for punct in end_punctuation:
        pos = generated_text.find(punct)
        if pos != -1 and (end_position == -1 or pos < end_position):
            end_position = pos

    # If punctuation is found, truncate the text at that point
    if end_position != -1:
        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()