File size: 1,207 Bytes
5846235
 
 
 
 
 
 
 
cb01412
5846235
 
 
 
 
 
 
 
cb01412
5846235
 
136f10e
 
5846235
 
 
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
import gradio as gr
from transformers import pipeline, set_seed

# Create text generation pipeline with GPT-2
generator = pipeline('text-generation', model='gpt2')

def generate_text(prompt, temperature, max_length, instruction):
    set_seed(42)
    result = generator(prompt + "\nAI: ", max_length=max_length, num_return_sequences=1, temperature=temperature)
    return result[0]['generated_text']

# Define Gradio interface
iface = gr.Interface(
    fn=generate_text, 
    inputs=[gr.inputs.Textbox(lines=3, label="Your Message"),
            gr.inputs.Slider(minimum=0.1, maximum=1.0, default=0.5, label="Temperature"),
            gr.inputs.Slider(minimum=10, maximum=200, default=100, label="Max Length"),
            gr.inputs.Textbox(default="This is a chat between the user and a truthful and intelligent AI. AI must answer very truthfully and accurately. The chat begins now.\nUser: hi\nAI: Hello, what do you need assistance with?\nUser: ", lines=2, label="AI Instruction")],
    outputs=gr.outputs.Textbox(label="AI Response"),
    layout="vertical",
    title="Chat with GPT-2",
    description="You can chat with the old GPT-2! Temperature and token limits are adjustable.",
)

iface.launch()