File size: 3,450 Bytes
0f14421 44c37a8 6cf06ca 44c37a8 0f14421 e14631d 439110e e51e935 439110e a6201ac ef2c1bc a6201ac 9bb98a4 439110e e14631d 44c37a8 e51e935 0f14421 a6201ac 0f14421 e51e935 8b0addf 5f4728f 8b0addf 0f0577d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# https://chat.lmsys.org/?leaderboard
import langchain
import transformers
# https://huggingface.co/spaces/joyson072/LLm-Langchain/blob/main/app.py
from langchain.llms import HuggingFaceHub
# for the chain and prompt
from langchain.prompts import PromptTemplate
from langchain.llms import HuggingFaceHub
from langchain.chains import LLMChain
#import model class and tokenizer
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
#import model class and tokenizer
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
###
# Definition of different purspose prompts
# https://huggingface.co/spaces/Chris4K/rlhf-arena/edit/main/app.py
####
def prompt_human_instruct(system_msg, history):
return system_msg.strip() + "\n" + \
"\n".join(["\n".join(["###Human: "+item[0], "###Assistant: "+item[1]])
for item in history])
def prompt_instruct(system_msg, history):
return system_msg.strip() + "\n" + \
"\n".join(["\n".join(["### Instruction: "+item[0], "### Response: "+item[1]])
for item in history])
def prompt_chat(system_msg, history):
return system_msg.strip() + "\n" + \
"\n".join(["\n".join(["USER: "+item[0], "ASSISTANT: "+item[1]])
for item in history])
def prompt_roleplay(system_msg, history):
return "<|system|>" + system_msg.strip() + "\n" + \
"\n".join(["\n".join(["<|user|>"+item[0], "<|model|>"+item[1]])
for item in history])
####
## Sentinent models
# https://huggingface.co/spaces/CK42/sentiment-model-comparison
# 1, 4 seem best for german
####
model_id_1 = "nlptown/bert-base-multilingual-uncased-sentiment"
model_id_2 = "microsoft/deberta-xlarge-mnli"
model_id_3 = "distilbert-base-uncased-finetuned-sst-2-english"
model_id_4 = "lordtt13/emo-mobilebert"
model_id_5 = "juliensimon/reviews-sentiment-analysis"
model_id_6 = "sbcBI/sentiment_analysis_model"
model_id_6 = "oliverguhr/german-sentiment-bert"
####
## Chat models
# https://huggingface.co/spaces/CK42/sentiment-model-comparison
# 1 seem best for testing
####
#download and setup the model and tokenizer
model_name = 'facebook/blenderbot-400M-distill'
tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
chat_model_facebook_blenderbot_400M_distill = "facebook/blenderbot-400M-distill"
chat_model_HenryJJ_vincua_13b = "HenryJJ/vincua-13b"
# https://colab.research.google.com/drive/1hrS6_g14EcOD4ezwSGlGX2zxJegX5uNX#scrollTo=NUwUR9U7qkld
#llm_hf = HuggingFaceHub(
# repo_id= chat_model_HenryJJ_vincua_13b,
# model_kwargs={"temperature":0.9 }
#)
text = "Why did the chicken cross the road?"
#output_question_1 = llm_hf(text)
#print(output_question_1)
###
## FACT EXTRACTION
###
fact_extraction_prompt = PromptTemplate(
input_variables=["text_input"],
template="Extract the key facts out of this text. Don't include opinions. Give each fact a number and keep them short sentences. :\n\n {text_input}"
)
fact_extraction_chain = LLMChain(llm=llm_hf, prompt=fact_extraction_prompt)
facts = fact_extraction_chain.run(text + " " +output_question_1)
print(facts)
def func (message):
inputs = tokenizer(message, return_tensors="pt")
result = model.generate(**inputs)
return tokenizer.decode(result[0])
import gradio as gr
app = gr.Interface(fn=func, inputs="textbox", outputs="textbox", title="Conversation Bot")
app.launch() |