Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model = AutoModelForCausalLM.from_pretrained("sakthi54321/Power_chat")
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("sakthi54321/Power_chat")
|
| 7 |
+
|
| 8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
+
model = model.to(device)
|
| 10 |
+
|
| 11 |
+
def generate(prompt):
|
| 12 |
+
inputs = tokenizer(f"Instruction: {prompt}\nOutput:", return_tensors="pt").to(device)
|
| 13 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 14 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
return response.split("Output:")[-1].strip()
|
| 16 |
+
|
| 17 |
+
gr.Interface(
|
| 18 |
+
fn=generate,
|
| 19 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask something..."),
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="TinyLLaMA Chat",
|
| 22 |
+
description="Fine-tuned TinyLLaMA model on Alpaca/CodeAlpaca instructions."
|
| 23 |
+
).launch()
|