Spaces:
Running
Running
# from transformers import pipeline | |
# import gradio as gr | |
# chatbot = pipeline("text-generation", model="unsloth/DeepSeek-R1-GGUF", trust_remote_code=True) | |
# def chat_with_bot(user_input): | |
# # Generate a response from the chatbot model | |
# response = chatbot(user_input) | |
# return response[0]['generated_text'] | |
# interface = gr.Interface( | |
# fn=chat_with_bot, # Function to call for processing the input | |
# inputs=gr.Textbox(label="Enter your message"), # User input (text) | |
# outputs=gr.Textbox(label="Chatbot Response", lines=10), # Model output (text) | |
# title="Chat with DeepSeek", # Optional: Add a title to your interface | |
# description="Chat with an AI model powered by DeepSeek!" # Optional: Add a description | |
# ) | |
# interface.launch() | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
import gradio as gr | |
# Load the model and tokenizer from Hugging Face | |
model_name = "unsloth/Llama-3.2-3B-Instruct" # Replace with your model | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
# Function to generate text | |
def generate_text(input_text, max_length=100, temperature=0.7, top_p=0.9): | |
# Tokenize the input text | |
inputs = tokenizer(input_text, return_tensors="pt") | |
# Generate text using the model | |
outputs = model.generate( | |
inputs["input_ids"], | |
max_length=max_length, | |
temperature=temperature, | |
top_p=top_p, | |
num_return_sequences=1, | |
no_repeat_ngram_size=2, | |
) | |
# Decode the generated text | |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return generated_text | |
# Gradio Interface | |
def gradio_interface(input_text, max_length, temperature, top_p): | |
generated_text = generate_text(input_text, max_length, temperature, top_p) | |
return generated_text | |
# Create the Gradio app | |
app = gr.Interface( | |
fn=gradio_interface, # Function to call | |
inputs=[ | |
gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Input Prompt"), | |
gr.Slider(minimum=10, maximum=500, value=100, step=10, label="Max Length"), | |
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"), | |
gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.1, label="Top-p (Nucleus Sampling)"), | |
], | |
outputs=gr.Textbox(lines=10, label="Generated Text"), | |
title="Text Generation with Hugging Face Transformers", | |
description="Generate text using a Hugging Face model.", | |
) | |
# Launch the app | |
app.launch() |