File size: 2,030 Bytes
966146c
d0a604a
6c68fe0
2e53cf6
 
6f2882b
 
2e53cf6
 
04e8cf9
6f2882b
f89e89e
d0a604a
04e8cf9
6f2882b
 
 
 
 
 
 
 
 
 
2e53cf6
 
6c68fe0
2e53cf6
 
 
 
090154d
2e53cf6
 
0015db3
2e53cf6
 
 
04e8cf9
0015db3
2bf87ab
6f2882b
 
 
2bf87ab
6f2882b
04e8cf9
6f2882b
04e8cf9
 
 
2e53cf6
 
04e8cf9
2bf87ab
4de02dd
 
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
import gradio as gr
from langchain.llms import HuggingFacePipeline
from transformers import AutoTokenizer, AutoModel
import transformers
import torch
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
import warnings
warnings.filterwarnings('ignore')


model = 'MD1998/FLAN-T5-V1'
tokenizer=AutoTokenizer.from_pretrained(model)

prompt_template=PromptTemplate(input_variables=["conversation"],
                               template="""\
You are a helpful, respectful, and honest assistant designed to improve English language skills. Always provide accurate and helpful responses to language improvement tasks, while ensuring safety and ethical standards. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased, positive, and focused on enhancing language skills.
If a question does not make sense or is not factually coherent, explain why instead of answering something incorrect. If you don't know the answer to a question, please don't share false information.
Your role is to guide users through various language exercises and challenges, helping them to practice and improve their English skills in a fun and engaging way. Always encourage users to try different approaches and provide constructive feedback to help them progress.

{conversation}
""")


pipeline=transformers.pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    device_map="auto",
    max_length=64,
    do_sample=True,
    top_k=10,
    top_p=5,
    num_return_sequences=1,
    eos_token_id=tokenizer.eos_token_id
    )

llm=HuggingFacePipeline(pipeline=pipeline, model_kwargs={'temperature':0.1})


chain = LLMChain(llm=llm, prompt=prompt_template, verbose=True)

def greet(prompt):
    response = chain.run(prompt)
    
    return response



iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()