MD1998 commited on
Commit
50cc5f8
·
verified ·
1 Parent(s): 63e0345

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -41
app.py CHANGED
@@ -44,29 +44,19 @@ import gradio as gr
44
 
45
 
46
  ##########################
47
- from langchain import PromptTemplate
48
- from langchain import LLMChain
49
- # from langchain.llms import CTransformers
50
- from langchain_community.llms import CTransformers
51
 
52
- from langchain.memory import ConversationBufferWindowMemory
 
53
 
54
- memory = ConversationBufferWindowMemory()
55
 
 
 
56
 
57
- # Update the model path to use the Hugging Face model identifier
58
- llm = CTransformers(model='MD1998/chating_beginners_v1',
59
- config={'max_new_tokens': 25,
60
- 'temperature': 0.2}
61
- )
62
-
63
- # convo = ConversationChain(
64
- # llm=llm,
65
- # memory=memory
66
- # )
67
- # convo.run("Who won the first cricket world cup?")
68
 
69
  def greet(my_prompt):
 
 
70
 
71
 
72
  DEFAULT_SYSTEM_PROMPT="""\
@@ -76,33 +66,14 @@ def greet(my_prompt):
76
 
77
  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. \n\n {text}
78
  """
79
-
80
-
81
-
82
-
83
-
84
-
85
- # DEFAULT_SYSTEM_PROMPT = """\
86
- # You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
87
-
88
- # If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."""
89
-
90
- # instruction = "Convert the following text from English to French: \n\n {text}"
91
- instruction = "Have a good conversation: \n\n {text}"
92
-
93
-
94
-
95
- prompt = PromptTemplate(template=DEFAULT_SYSTEM_PROMPT, input_variables=["text"])
96
-
97
-
98
- LLM_Chain = LLMChain(prompt=prompt, llm=llm, memory=memory)
99
-
100
- # print(LLM_Chain.run("How are you"))
101
-
102
 
 
 
 
 
103
 
104
 
105
- return LLM_Chain.run(my_prompt)
106
 
107
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
108
  iface.launch()
 
44
 
45
 
46
  ##########################
 
 
 
 
47
 
48
+ from transformers import T5Tokenizer, DataCollatorForSeq2Seq
49
+ from transformers import T5ForConditionalGeneration, Seq2SeqTrainingArguments, Seq2SeqTrainer, AutoModelForSeq2SeqLM
50
 
51
+ model = "MD1998/chating_beginners_v1"
52
 
53
+ finetuned_model = T5ForConditionalGeneration.from_pretrained(model)
54
+ tokenizer = T5Tokenizer.from_pretrained(model)
55
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  def greet(my_prompt):
58
+ my_question = my_prompt
59
+ inputs = "Your name is Nemo, Please answer to this question in few words: " + my_question
60
 
61
 
62
  DEFAULT_SYSTEM_PROMPT="""\
 
66
 
67
  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. \n\n {text}
68
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
+ inputss = tokenizer(inputs, return_tensors="pt")
71
+ outputs = finetuned_model.generate(**inputss)
72
+ answer = tokenizer.decode(outputs[0])
73
+ from textwrap import fill
74
 
75
 
76
+ return fill(answer, width=80)
77
 
78
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
79
  iface.launch()