Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,24 @@
|
|
1 |
-
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import gradio as gr
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
from peft import PeftModel
|
@@ -13,14 +32,13 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
13 |
torch_dtype="auto",
|
14 |
device_map="auto",
|
15 |
trust_remote_code=True,
|
16 |
-
use_cache=False
|
17 |
)
|
18 |
|
19 |
# Load your fine-tuned adapter
|
20 |
model = PeftModel.from_pretrained(model, "KlemGunn0519/Mighty_Mountain_Ski_Resort")
|
21 |
|
22 |
def respond(message, history):
|
23 |
-
# Format prompt as in training
|
24 |
prompt = f"### Instruction\n{message}\n\n### Response"
|
25 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
26 |
|
@@ -33,23 +51,18 @@ def respond(message, history):
|
|
33 |
pad_token_id=tokenizer.eos_token_id
|
34 |
)
|
35 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
36 |
-
|
37 |
-
# Extract only the assistant's response (after "### Response")
|
38 |
-
try:
|
39 |
-
return response.split("### Response")[-1].strip()
|
40 |
-
except:
|
41 |
-
return response
|
42 |
|
43 |
-
#
|
44 |
demo = gr.ChatInterface(
|
45 |
fn=respond,
|
46 |
title="🎿 Mighty Mountain Ski Resort Assistant",
|
47 |
-
description="Ask about lift tickets, trail conditions, hours,
|
48 |
examples=[
|
49 |
"What are daily lift ticket prices?",
|
50 |
-
"Do you have night skiing?",
|
51 |
"What's the best beginner slope?",
|
52 |
-
"
|
|
|
53 |
],
|
54 |
theme="soft",
|
55 |
retry_btn=None,
|
|
|
1 |
+
import subprocess
|
2 |
+
import sys
|
3 |
+
import os
|
4 |
|
5 |
+
# Install required packages directly in the app
|
6 |
+
def install(package):
|
7 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
8 |
+
|
9 |
+
print("Installing required packages...")
|
10 |
+
install("transformers==4.56.0")
|
11 |
+
install("torch==2.3.0")
|
12 |
+
install("peft==0.12.0")
|
13 |
+
install("accelerate==0.28.0")
|
14 |
+
install("bitsandbytes==0.43.0")
|
15 |
+
install("sentencepiece")
|
16 |
+
install("protobuf")
|
17 |
+
install("gradio==5.27.0")
|
18 |
+
|
19 |
+
print("All packages installed. Loading model...")
|
20 |
+
|
21 |
+
# Now import after installation
|
22 |
import gradio as gr
|
23 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
24 |
from peft import PeftModel
|
|
|
32 |
torch_dtype="auto",
|
33 |
device_map="auto",
|
34 |
trust_remote_code=True,
|
35 |
+
use_cache=False
|
36 |
)
|
37 |
|
38 |
# Load your fine-tuned adapter
|
39 |
model = PeftModel.from_pretrained(model, "KlemGunn0519/Mighty_Mountain_Ski_Resort")
|
40 |
|
41 |
def respond(message, history):
|
|
|
42 |
prompt = f"### Instruction\n{message}\n\n### Response"
|
43 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
44 |
|
|
|
51 |
pad_token_id=tokenizer.eos_token_id
|
52 |
)
|
53 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
54 |
+
return response.split("### Response")[-1].strip()
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
# Create Gradio interface
|
57 |
demo = gr.ChatInterface(
|
58 |
fn=respond,
|
59 |
title="🎿 Mighty Mountain Ski Resort Assistant",
|
60 |
+
description="Ask about lift tickets, trail conditions, hours, and more!",
|
61 |
examples=[
|
62 |
"What are daily lift ticket prices?",
|
|
|
63 |
"What's the best beginner slope?",
|
64 |
+
"Do you offer ski rentals?",
|
65 |
+
"When does the resort open for the season?"
|
66 |
],
|
67 |
theme="soft",
|
68 |
retry_btn=None,
|