File size: 951 Bytes
49c0097
959e25e
49c0097
d56e863
 
959e25e
49c0097
959e25e
309768d
d56e863
 
 
 
 
 
 
 
 
 
49c0097
959e25e
309768d
 
 
 
 
d56e863
309768d
49c0097
959e25e
 
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
import gradio as gr
from transformers import pipeline

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

# Inference function
def generate_response(prompt):
    # Generate text with specific parameters
    response = generator(
        prompt,
        max_length=150,  # Increase max length for more comprehensive responses
        num_return_sequences=1,
        temperature=0.7,  # Lower for more deterministic responses
        top_k=50,         # Consider the top 50 tokens for diversity
        top_p=0.95        # Cumulative probability for diversity
    )
    return response[0]['generated_text'].strip()  # Clean up the output

# Gradio interface
interface = gr.Interface(
    fn=generate_response, 
    inputs="text", 
    outputs="text", 
    title="Conversational LLM",
    description="Enter a prompt to generate a relevant and coherent response."
)

# Launch the interface
interface.launch()