Spaces:
Sleeping
Sleeping
Commit
Β·
84913ef
1
Parent(s):
1ac6501
add
Browse files- app2.py +0 -56
- requirements.txt +2 -2
app2.py
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import pipeline
|
3 |
-
import gradio as gr
|
4 |
-
|
5 |
-
# λͺ¨λΈ λ‘λ
|
6 |
-
def load_model(model_name="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"):
|
7 |
-
pipe = pipeline(
|
8 |
-
"text-generation",
|
9 |
-
model=model_name,
|
10 |
-
device_map="auto",
|
11 |
-
torch_dtype=torch.float16,
|
12 |
-
trust_remote_code=True,
|
13 |
-
truncation=True,
|
14 |
-
max_new_tokens=2048
|
15 |
-
)
|
16 |
-
return pipe
|
17 |
-
|
18 |
-
# μ±λ΄ μλ΅ μμ± ν¨μ
|
19 |
-
def chat(message, history):
|
20 |
-
pipe = load_model()
|
21 |
-
prompt = f"Human: {message}\n\nAssistant:"
|
22 |
-
|
23 |
-
response = pipe(
|
24 |
-
prompt,
|
25 |
-
max_new_tokens=2048,
|
26 |
-
temperature=0.7,
|
27 |
-
do_sample=True,
|
28 |
-
truncation=True,
|
29 |
-
pad_token_id=50256
|
30 |
-
)
|
31 |
-
|
32 |
-
# μλ΅ μΆμΆ λ° μ²λ¦¬
|
33 |
-
try:
|
34 |
-
bot_text = response[0]["generated_text"]
|
35 |
-
bot_text = bot_text.split("Assistant:")[-1].strip()
|
36 |
-
if "</think>" in bot_text:
|
37 |
-
bot_text = bot_text.split("</think>")[-1].strip()
|
38 |
-
except:
|
39 |
-
bot_text = "Sorry, there was a problem generating the response."
|
40 |
-
|
41 |
-
return bot_text
|
42 |
-
|
43 |
-
# Gradio μΈν°νμ΄μ€ μ€μ
|
44 |
-
demo = gr.ChatInterface(
|
45 |
-
chat,
|
46 |
-
chatbot=gr.Chatbot(height=600),
|
47 |
-
textbox=gr.Textbox(placeholder="Enter your message...", container=False, scale=7),
|
48 |
-
title="DeepSeek-R1 Chatbot",
|
49 |
-
description="DeepSeek-R1-Distill-Qwen-1.5B λͺ¨λΈμ μ¬μ©ν λν ν
μ€νΈμ© λ°λͺ¨μ
λλ€.",
|
50 |
-
examples=["Hello", "Who are you?", "What can you do?"],
|
51 |
-
theme=gr.themes.Soft()
|
52 |
-
)
|
53 |
-
|
54 |
-
# μλ² μ€ν
|
55 |
-
if __name__ == "__main__":
|
56 |
-
demo.launch(share=True, server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
streamlit
|
2 |
torch
|
3 |
transformers>=4.35.0
|
4 |
-
accelerate
|
5 |
-
|
|
|
1 |
streamlit
|
2 |
torch
|
3 |
transformers>=4.35.0
|
4 |
+
accelerate>=0.20.0
|
5 |
+
|