Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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()
|