File size: 699 Bytes
a137c56
 
45efcd3
6b71862
3350859
45efcd3
 
6b71862
 
 
 
 
 
 
 
 
 
 
a137c56
 
 
22844e5
40a1bb1
a137c56
 
6b71862
 
40a1bb1
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
import gradio as gr
from transformers import pipeline

# Use a lighter model: distilgpt2
generator = pipeline("text-generation", model="distilgpt2")

def generate_completion(prompt):
    outputs = generator(
        prompt,
        max_length=50,
        do_sample=True,
        temperature=1.1,  # slightly higher for more randomness
        top_k=50,
        top_p=0.95
    )
    generated_text = outputs[0]['generated_text']
    # Remove the original prompt from the returned completion
    return generated_text[len(prompt):].strip()

iface = gr.Interface(
    fn=generate_completion,
    inputs=gr.Textbox(lines=1, placeholder="Enter your text here..."),
    outputs="text"
)

iface.launch()