binqiangliu commited on
Commit
b8ba1e0
Β·
1 Parent(s): 0f80c72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -22
app.py CHANGED
@@ -1,34 +1,47 @@
1
  from transformers import pipeline, Conversation
2
  import gradio as gr
3
 
 
4
 
5
- #θΏ™δΈͺSpaceδΈ»θ¦ζ˜―ζΌ”η€ΊδΊ†ε―δ»₯η›΄ζŽ₯使用Huggingfaceηš„pipelineζž„ε»ΊAIAppοΌŒη„ΆεŽθΏ˜εˆšε₯½ε―δ»₯ε’ŒGradioηš„ChatInterfaceε―ΉεΊ”δΈŠοΌ
6
- chatbot = pipeline(model="facebook/blenderbot-400M-distill") #Working!
7
- #https://huggingface.co/facebook/blenderbot-400M-distill/tree/main
8
- #θΏ™δΈͺζ¨‘εž‹ζ–‡δ»Άε€§ε°οΌš730MBζˆ–1.46GB
9
 
10
- #https://huggingface.co/facebook/blenderbot-400M-distill/tree/main?library=true
11
- # Use a pipeline as a high-level helper
12
- #from transformers import pipeline
13
- #pipe = pipeline("conversational", model="facebook/blenderbot-400M-distill")
14
 
15
- #chatbot = pipeline(model="HuggingFaceH4/starchat-beta")
16
- #https://huggingface.co/HuggingFaceH4/starchat-beta/tree/main
17
- #η”±δΊŽθΏ™δΈͺζ¨‘εž‹ε€ͺε€§δΊ†οΌˆ9.96+9.86+9.86+1.36GBοΌ‰οΌŒδΌšε―Όθ‡΄ε¦‚δΈ‹ι”™θ――οΌš
18
- #Runtime error
19
- #Memory limit exceeded (16Gi)
20
 
21
- #chatbot = pipeline(model="...")
22
 
23
- message_list = []
24
- response_list = []
 
 
 
25
 
26
- def vanilla_chatbot(message, history):
27
- conversation = Conversation(text=message, past_user_inputs=message_list, generated_responses=response_list)
28
- conversation = chatbot(conversation)
29
 
30
- return conversation.generated_responses[-1]
31
 
32
- demo_chatbot = gr.ChatInterface(vanilla_chatbot, title="Vanilla Chatbot", description="Enter text to start chatting.")
 
 
 
 
 
33
 
34
- demo_chatbot.launch()
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline, Conversation
2
  import gradio as gr
3
 
4
+ #https://huggingface.co/TheBloke/starchat-beta-GPTQ
5
 
6
+ from transformers import AutoTokenizer, pipeline, logging
7
+ from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
8
+ import argparse
 
9
 
10
+ model_name_or_path = "TheBloke/starchat-beta-GPTQ"
11
+ # Or to load it locally, pass the local download path
12
+ # model_name_or_path = "/path/to/models/The_Bloke_starchat-beta-GPTQ"
 
13
 
14
+ use_triton = False
 
 
 
 
15
 
16
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
17
 
18
+ model = AutoGPTQForCausalLM.from_quantized(model_name_or_path,
19
+ use_safetensors=True,
20
+ #device="cuda:0",
21
+ use_triton=use_triton,
22
+ quantize_config=None)
23
 
24
+ # Prevent printing spurious transformers error when using pipeline with AutoGPTQ
25
+ logging.set_verbosity(logging.CRITICAL)
 
26
 
27
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
28
 
29
+ prompt_template = "<|system|>\n<|end|>\n<|user|>\n{query}<|end|>\n<|assistant|>"
30
+ prompt = prompt_template.format(query="How do I sort a list in Python?")
31
+ # We use a special <|end|> token with ID 49155 to denote ends of a turn
32
+ outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.2, top_k=50, top_p=0.95, eos_token_id=49155)
33
+ # You can sort a list in Python by using the sort() method. Here's an example:\n\n```\nnumbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]\nnumbers.sort()\nprint(numbers)\n```\n\nThis will sort the list in place and print the sorted list.
34
+ print(outputs[0]['generated_text'])
35
 
36
+ #message_list = []
37
+ #response_list = []
38
+
39
+ #def vanilla_chatbot(message, history):
40
+ # conversation = Conversation(text=message, past_user_inputs=message_list, generated_responses=response_list)
41
+ # conversation = chatbot(conversation)
42
+
43
+ # return conversation.generated_responses[-1]
44
+
45
+ #demo_chatbot = gr.ChatInterface(vanilla_chatbot, title="Vanilla Chatbot", description="Enter text to start chatting.")
46
+
47
+ #demo_chatbot.launch()