K-Meng commited on
Commit
f8d742e
·
verified ·
1 Parent(s): e8f7b06

Then commit and push

Browse files

$ git add app.py
$ git commit -m "Add application file"
$ git push

Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
3
+ import torch
4
+
5
+ model_id = "your-username/phi3-mini-4k-finetuned"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ model_id,
10
+ torch_dtype=torch.float32,
11
+ device_map="cpu"
12
+ )
13
+
14
+ def chat(prompt):
15
+ inputs = tokenizer(prompt, return_tensors="pt")
16
+ output = model.generate(
17
+ **inputs,
18
+ max_new_tokens=256,
19
+ temperature=0.7
20
+ )
21
+ return tokenizer.decode(output[0], skip_special_tokens=True)
22
+
23
+ gr.Interface(
24
+ fn=chat,
25
+ inputs="text",
26
+ outputs="text",
27
+ title="Phi-3 Mini 4K Instruct (Fine-Tuned)"
28
+ ).launch()