File size: 950 Bytes
6ca34cf
 
 
0d9b453
6ca34cf
0d9b453
899a5f6
 
6ca34cf
 
d733851
 
 
899a5f6
6ca34cf
b4a0c25
6ca34cf
 
 
f0b7b32
 
0d9b453
 
6ca34cf
 
 
 
 
 
0866bfe
f0b7b32
 
 
 
0866bfe
 
 
dedd577
f0b7b32
 
dedd577
b09cd28
 
0866bfe
 
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
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

torch.random.manual_seed(0)

proc_model = AutoModelForCausalLM.from_pretrained(
    "microsoft/Phi-3-mini-4k-instruct",
    trust_remote_code=True, 
)

proc_model.to("cpu")
proc_model.eval()
proc_tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")



proc_pipe = pipeline(
    "text-generation",
    model=proc_model,
    tokenizer=proc_tokenizer,
)

generation_args = {
    "max_new_tokens": 500,
    "return_full_text": False,
    "temperature": 0.0,
    "do_sample": False,
}

def generate_response(inputs):
    output = proc_pipe(inputs, **generation_args)
    return output[0]['generated_text']



# Create a Gradio interface
iface = gr.Interface(
    fn=generate_response, 
    inputs=[gr.Textbox(lines=5, placeholder="Enter your prompt here...")]
    outputs=gr.Textbox()
)

# Launch the interface
iface.launch()