added files
Browse files- app.py +35 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
+
|
4 |
+
model_path = "gupta1912/phi-2-custom-oasst1"
|
5 |
+
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
8 |
+
|
9 |
+
def generate_text(prompt, response_length):
|
10 |
+
|
11 |
+
prompt = str(prompt)
|
12 |
+
max_len = int(response_length)
|
13 |
+
|
14 |
+
gen = pipeline('text-generation', model=model, tokenizer=tokenizer, max_length=max_len)
|
15 |
+
result = gen(f"<s>[INST] {prompt} [/INST]")
|
16 |
+
output_msg = result[0]['generated_text'].split("[/INST] ")[1]
|
17 |
+
return output_msg
|
18 |
+
|
19 |
+
def gradio_fn(prompt, response_length):
|
20 |
+
output_txt_msg = generate_text(prompt, response_length)
|
21 |
+
return output_txt_msg
|
22 |
+
|
23 |
+
markdown_description = """
|
24 |
+
- This is a Gradio app that answers the query you ask it
|
25 |
+
- Uses **microsoft/phi-2** model finetuned on **OpenAssistant/oasst1** dataset
|
26 |
+
"""
|
27 |
+
demo = gr.Interface(fn=gradio_fn,
|
28 |
+
inputs=[gr.Textbox(info="How may I help you ? please enter your prompt here..."),
|
29 |
+
gr.Slider(value=50, minimum=50, maximum=300, \
|
30 |
+
info="Choose a response length min chars=50, max=300")],
|
31 |
+
outputs=gr.Textbox(),
|
32 |
+
title="custom trained phi2 - Dialog Partner",
|
33 |
+
description=markdown_description)
|
34 |
+
|
35 |
+
demo.queue().launch(share=True, debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.50.2
|
2 |
+
torch>=2.1.0
|
3 |
+
transformers
|
4 |
+
tokenizers
|
5 |
+
einops
|