Spaces:
Paused
Paused
Upload 2 files
Browse files- app.py +52 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from unsloth import FastLanguageModel
|
| 3 |
+
import torch
|
| 4 |
+
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
|
| 5 |
+
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
|
| 6 |
+
load_in_4bit = True
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 10 |
+
model_name = "Mudditha/test-phi-3", # YOUR MODEL YOU USED FOR TRAINING
|
| 11 |
+
max_seq_length = max_seq_length,
|
| 12 |
+
dtype = dtype,
|
| 13 |
+
load_in_4bit = load_in_4bit,
|
| 14 |
+
)
|
| 15 |
+
FastLanguageModel.for_inference(model)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
inf_prompt_1 = """
|
| 19 |
+
|
| 20 |
+
### Input:
|
| 21 |
+
{}
|
| 22 |
+
|
| 23 |
+
### Response:
|
| 24 |
+
{}"""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def print_output(input):
|
| 28 |
+
inputs = tokenizer(
|
| 29 |
+
[
|
| 30 |
+
inf_prompt_1.format(
|
| 31 |
+
input, # instruction
|
| 32 |
+
"", # output - leave this blank for generation!
|
| 33 |
+
),
|
| 34 |
+
], return_tensors = "pt").to("cuda")
|
| 35 |
+
|
| 36 |
+
# outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
|
| 37 |
+
# tokenizer.batch_decode(outputs)
|
| 38 |
+
|
| 39 |
+
outputs = model.generate(**inputs, max_new_tokens = 100, use_cache = True)
|
| 40 |
+
return tokenizer.batch_decode(outputs)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# Streamlit app UI
|
| 44 |
+
st.title("Echo Input Example")
|
| 45 |
+
|
| 46 |
+
# Text box for user input
|
| 47 |
+
user_input = st.text_input("Type something here:")
|
| 48 |
+
|
| 49 |
+
# Button to submit input
|
| 50 |
+
if st.button("Submit"):
|
| 51 |
+
# Reprint the user input
|
| 52 |
+
st.write(f"You typed: {print_output(user_input)}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
unsloth
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# This is only needed for local deployment
|
| 6 |
+
streamlit
|