Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,25 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import pipeline
|
3 |
import os
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
model_id = 'dicta-il/dictalm-7b-instruct'
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
local_rank = int(os.getenv('LOCAL_RANK', '0'))
|
13 |
-
world_size = int(os.getenv('WORLD_SIZE', '1'))
|
14 |
-
|
15 |
-
# 讘讚讬拽转 讛转拽谉 - GPU 讗讜 CPU
|
16 |
-
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
17 |
-
print('Using device:', device)
|
18 |
-
print()
|
19 |
-
|
20 |
-
# 讬爪讬专转 讛诪谞讜注 注诐 pipeline
|
21 |
-
generator = pipeline('text-generation', model=model_id,
|
22 |
-
tokenizer=model_id,
|
23 |
-
torch_dtype=torch.float16 if device.type == 'cuda' else torch.float32,
|
24 |
-
use_fast=should_use_fast,
|
25 |
-
trust_remote_code=True,
|
26 |
-
device_map="auto" if device.type == 'cuda' else None)
|
27 |
|
28 |
# 驻讜谞拽爪讬讬转 讬爪讬专转 讛讟拽住讟
|
29 |
def chat_with_model(history):
|
30 |
prompt = history[-1]["content"]
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
return history + [{"role": "bot", "content": result}]
|
33 |
|
34 |
# 讬爪讬专转 诪诪砖拽 诪转拽讚诐 注诐 Gradio 讘爪讜专转 爪'讟-讘讜讟 讘住讙谞讜谉 讗拽讚诪讬
|
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from huggingface_hub import InferenceApi
|
4 |
|
5 |
model_id = 'dicta-il/dictalm-7b-instruct'
|
6 |
|
7 |
+
# 讬爪讬专转 API 砖诇 Hugging Face
|
8 |
+
api_key = os.getenv('HUGGINGFACE_API_KEY', '')
|
9 |
+
generator = InferenceApi(repo_id=model_id, token=api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# 驻讜谞拽爪讬讬转 讬爪讬专转 讛讟拽住讟
|
12 |
def chat_with_model(history):
|
13 |
prompt = history[-1]["content"]
|
14 |
+
response = generator(prompt, parameters={
|
15 |
+
"do_sample": True,
|
16 |
+
"min_length": 20,
|
17 |
+
"max_length": 64,
|
18 |
+
"top_k": 40,
|
19 |
+
"top_p": 0.92,
|
20 |
+
"temperature": 0.9
|
21 |
+
})
|
22 |
+
result = response["generated_text"]
|
23 |
return history + [{"role": "bot", "content": result}]
|
24 |
|
25 |
# 讬爪讬专转 诪诪砖拽 诪转拽讚诐 注诐 Gradio 讘爪讜专转 爪'讟-讘讜讟 讘住讙谞讜谉 讗拽讚诪讬
|