File size: 873 Bytes
741f50b
 
 
44e9179
 
741f50b
44e9179
741f50b
44e9179
 
 
 
 
 
 
741f50b
 
d6c7f33
741f50b
d6c7f33
 
 
44e9179
 
741f50b
 
 
 
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

# Load the distilgpt2 model
generator = pipeline("text-generation", model="distilgpt2")

# Define the function to generate dynamic responses
def generate_text(prompt):
    result = generator(
        prompt, 
        max_length=50,  # Control the length of the output
        temperature=0.7,  # Balance between predictability and creativity
        top_p=0.9,  # Focus on likely words to maintain relevance
        num_return_sequences=1  # Return only one response
    )
    return result[0]['generated_text']

# Create the Gradio interface
interface = gr.Interface(
    fn=generate_text,
    inputs="text",
    outputs="text",
    title="Conversational AI with distilgpt2",
    description="Enter instructions or prompts, and the model will generate text accordingly.",
)

# Launch the interface
interface.launch()