Tirendaz commited on
Commit
00456d8
·
1 Parent(s): b8cd69d

add files

Browse files
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ generator = pipeline("text-generation",
5
+ model="microsoft/Phi-4-mini-instruct",
6
+ torch_dtype="auto",
7
+ device_map="auto")
8
+
9
+ def generate_text(prompt):
10
+ messages = [
11
+ {"role":"system", "content":"You are a helpful AI assistant"},
12
+ {"role":"user", "content":prompt}
13
+ ]
14
+ outputs = generator(
15
+ messages,
16
+ max_new_tokens = 100,
17
+ do_sample=True,
18
+ temperature=0.7,
19
+ return_full_text = False
20
+ )
21
+ return outputs[0]["generated_text"]
22
+
23
+ demo = gr.Interface(
24
+ fn = generate_text,
25
+ inputs = gr.Textbox(label="Give an input"),
26
+ outputs= gr.Textbox(label="Output"),
27
+ title="Text Generation App"
28
+ )
29
+
30
+ if __name__ == "__main__":
31
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ gradio
4
+ accelerate
5
+ safetensors