manojapi / app.py
ManojINaik's picture
3
d56e863 verified
raw
history blame
951 Bytes
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()