mkthoma commited on
Commit
91be14d
1 Parent(s): 2bbdaf0

update app

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ model_path = "finetuned_phi2"
6
+ model = AutoModelForCausalLM.from_pretrained(model_path)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
8
+
9
+ gen = pipeline('text-generation', model=model, tokenizer=tokenizer)
10
+ result = gen(prompt)
11
+ print(result[0]['generated_text'])
12
+
13
+
14
+ def generate(prompt, history, temperature=0.3, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0,):
15
+ temperature = float(temperature)
16
+ if temperature < 1e-2:
17
+ temperature = 1e-2
18
+ top_p = float(top_p)
19
+
20
+ generate_kwargs = dict(temperature=temperature,
21
+ max_new_tokens=max_new_tokens,
22
+ top_p=top_p,
23
+ repetition_penalty=repetition_penalty,
24
+ do_sample=True,
25
+ seed=42)
26
+
27
+ #output = gen(prompt, **generate_kwargs)
28
+ output = gen(prompt)
29
+ return output[0]['generated_text']
30
+
31
+ bbchatbot = gr.Chatbot(
32
+ avatar_images=[".logo/user logo 2.png", ".logo/bot logo.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
33
+
34
+ demo = gr.ChatInterface(fn=generate,
35
+ chatbot=bbchatbot,
36
+ title="🧑🏽‍💻Microsoft Phi2 Chatbot🤖"
37
+ )
38
+
39
+ demo.queue().launch(show_api=False)