Spaces:
Sleeping
Sleeping
File size: 1,349 Bytes
3a409b6 8f8506e 3a409b6 8f8506e 3a409b6 8f8506e 3a409b6 8f8506e 3a409b6 8f8506e 746bc15 662955c 8f8506e 13ff6c9 746bc15 8f8506e 3a409b6 746bc15 3a409b6 746bc15 8f8506e 3a409b6 8f8506e 3a409b6 | 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 40 41 42 43 44 45 46 47 48 | import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "sakthi54321/power_ai"
# Load model + tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
device_map="auto"
)
# Simple function: one input → one output
def ask_model(prompt):
# force very direct answer
input_text = f"Question: {prompt}\nAnswer:"
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=800, # keep answers short
pad_token_id=tokenizer.eos_token_id,
do_sample=True,
top_p=0.9,
temperature=0.7
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# only take the text after "Answer:"
if "Answer:" in response:
response = response.split("Answer:")[-1].strip()
return response
# Gradio UI (straightforward)
demo = gr.Interface(
fn=ask_model,
inputs=gr.Textbox(label="Ask something", placeholder="Type your question here..."),
outputs=gr.Textbox(label="Model Response"),
title="🤖 Power AI",
description="Straightforward Q&A with your trained model"
)
demo.launch()
|