Spaces:
Paused
Paused
File size: 1,569 Bytes
4d6cb9b 49830c8 ef3f9be 4d6cb9b 49830c8 75e75ed 4d6cb9b 49830c8 4d6cb9b ad04461 ef3f9be 49830c8 ad04461 |
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 33 34 35 36 37 38 39 |
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()
|