Gervacius commited on
Commit
8c07f2f
·
verified ·
1 Parent(s): 69e9526

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+ import gradio as gr
3
+
4
+ # Load the model and tokenizer
5
+ model_name = "microsoft/phi-4"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ def predict(input_text):
10
+ # Tokenize input and generate text
11
+ inputs = tokenizer(input_text, return_tensors="pt")
12
+ outputs = model.generate(**inputs)
13
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+
15
+ # Create a Gradio interface
16
+ interface = gr.Interface(
17
+ fn=predict,
18
+ inputs=gr.Textbox(label="Input Text"),
19
+ outputs=gr.Textbox(label="Generated Output"),
20
+ title="Phi-4 Model",
21
+ description="Generate text using the microsoft/phi-4 model."
22
+ )
23
+
24
+ # Launch the interface
25
+ interface.launch()