Spaces:
Sleeping
Sleeping
Create App.py
Browse files
App.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_id = "sakthi54321/power_ai" # your uploaded model
|
| 6 |
+
|
| 7 |
+
# Load model and tokenizer
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
model_id,
|
| 11 |
+
torch_dtype=torch.float16,
|
| 12 |
+
device_map="auto"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Chat function
|
| 16 |
+
def chat(message, history=[]):
|
| 17 |
+
inputs = tokenizer(message, return_tensors="pt").to(model.device)
|
| 18 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 19 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 20 |
+
return response
|
| 21 |
+
|
| 22 |
+
# Gradio UI
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=chat,
|
| 25 |
+
inputs="text",
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="Power AI Chatbot",
|
| 28 |
+
description="Chat with your fine-tuned Power AI model"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
demo.launch()
|