Jatinydv commited on
Commit
4cb6620
1 Parent(s): d06cf0c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms.ctransformers import CTransformers
2
+ from langchain.chains.llm import LLMChain
3
+ from langchain.prompts import PromptTemplate
4
+ import os
5
+ import gradio as gr
6
+ import time
7
+
8
+ custom_prompt_template=""""
9
+ You are an AI coding assistant and your task is to solve coding problems
10
+ and return code snippets based on the user's query. Below is the user's query.
11
+ Query:{query}
12
+ You just return the helpful code and related details.
13
+ Helpful code and related details:
14
+ """
15
+
16
+ def set_custom_prompt():
17
+ prompt=PromptTemplate(
18
+ template=custom_prompt_template,
19
+ input_variables=['query']
20
+ )
21
+ return prompt
22
+
23
+ def load_model():
24
+ llm=CTransformers(
25
+ model='codellama-7b-instruct.ggmlv3.Q4_K_M.bin',
26
+ model_type='llama',
27
+ max_new_tokens=1096,
28
+ temperature=0.2,
29
+ repetition_penalty=1.13
30
+
31
+ )
32
+
33
+ return llm
34
+
35
+ def chain_pipeline():
36
+ llm=load_model()
37
+ qa_prompt=set_custom_prompt()
38
+ qa_chain=LLMChain(
39
+ prompt=qa_prompt,
40
+ llm=llm
41
+ )
42
+ return qa_chain
43
+
44
+ llmchain=chain_pipeline()
45
+
46
+ def bot(query):
47
+ llm_response=llmchain.run({'query':query})
48
+ return llm_response
49
+
50
+ with gr.Blocks(title="Can AI code ? ") as demo:
51
+ gr.Markdown('# Code LLAMA demo')
52
+ chatbot=gr.Chatbot([],elem_id='chatbot',height=700)
53
+ msg=gr.Textbox()
54
+ clear=gr.ClearButton([msg,chatbot])
55
+
56
+
57
+ def respond(message,chat_history):
58
+ bot_message=bot(message)
59
+ chat_history.append((message,bot_message))
60
+ time.sleep(2)
61
+ return "",chat_history
62
+
63
+ msg.submit(respond,[msg,chatbot],[msg,chatbot])
64
+
65
+
66
+ demo.launch()