Spaces:
Paused
Paused
import gradio as gr | |
from transformers import AutoTokenizer, AutoModelForCausalLM | |
import torch | |
# Load the tokenizer from the Hugging Face Hub | |
tokenizer = AutoTokenizer.from_pretrained("adarsh3601/my_gemma3_pt") | |
# Load the model from Hugging Face Hub (Assuming you are using a transformer model here) | |
model = AutoModelForCausalLM.from_pretrained("adarsh3601/my_gemma3_pt") | |
# Function to generate response using the model | |
def generate_response(input_text): | |
# Tokenize the input text | |
inputs = tokenizer(input_text, return_tensors="pt") | |
# Generate output using the model | |
with torch.no_grad(): # Disable gradients for inference | |
outputs = model.generate(inputs['input_ids'], max_length=50) # You can adjust max_length and other parameters | |
# Decode the output and return it | |
return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
# Create a Gradio interface | |
def create_gradio_interface(): | |
# Interface with a text input and a text output | |
interface = gr.Interface( | |
fn=generate_response, # Function to call for generation | |
inputs=gr.Textbox(label="Enter Input Text"), # Textbox for user input | |
outputs=gr.Textbox(label="Generated Response"), # Textbox for output text | |
title="Text Generation with My Model", # Title for the interface | |
description="Enter some text to generate a response using the trained model." # Description | |
) | |
return interface | |
# Launch the Gradio interface | |
if __name__ == "__main__": | |
interface = create_gradio_interface() | |
interface.launch() | |