File size: 818 Bytes
00456d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline 
import gradio as gr 

generator = pipeline("text-generation", 
                     model="microsoft/Phi-4-mini-instruct",
                     torch_dtype="auto",
                     device_map="auto")

def generate_text(prompt):
    messages = [
        {"role":"system", "content":"You are a helpful AI assistant"},
        {"role":"user", "content":prompt}
    ]
    outputs = generator(
        messages,
        max_new_tokens = 100,
        do_sample=True,
        temperature=0.7,
        return_full_text = False
    )
    return outputs[0]["generated_text"]

demo = gr.Interface(
    fn = generate_text,
    inputs = gr.Textbox(label="Give an input"),
    outputs= gr.Textbox(label="Output"),
    title="Text Generation App"
)

if __name__ == "__main__":
    demo.launch()