jefalod commited on
Commit
5a150bf
·
verified ·
1 Parent(s): 3eb42eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import gradio as gr
4
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
5
+
6
+ model = AutoModelForCausalLM.from_pretrained("trained_model", device_map="auto")
7
+ tokenizer = AutoTokenizer.from_pretrained("trained_model")
8
+
9
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
10
+
11
+ def chatbot(instruction):
12
+ prompt = f"### Instruction:\n{instruction}\n\n### Response:\n"
13
+ response = pipe(prompt, max_new_tokens=100)[0]['generated_text']
14
+ return response[len(prompt):].strip()
15
+
16
+ gr.Interface(
17
+ fn=chatbot,
18
+ inputs="text",
19
+ outputs="text",
20
+ title="TinyLlama QLoRA Support Bot"
21
+ ).launch()