Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,62 +5,60 @@ 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='TheBloke/CodeLlama-7B-Instruct-GGML',
|
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 |
-
|
|
|
|
|
49 |
|
50 |
-
with gr.Blocks(title="Can AI code ?
|
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 |
-
|
58 |
-
|
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()
|
|
|
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='TheBloke/CodeLlama-7B-Instruct-GGML',
|
26 |
model_type='llama',
|
27 |
max_new_tokens=1096,
|
28 |
temperature=0.2,
|
29 |
repetition_penalty=1.13
|
|
|
30 |
)
|
|
|
31 |
return llm
|
32 |
|
33 |
def chain_pipeline():
|
34 |
+
llm = load_model()
|
35 |
+
qa_prompt = set_custom_prompt()
|
36 |
+
qa_chain = LLMChain(
|
37 |
prompt=qa_prompt,
|
38 |
llm=llm
|
39 |
)
|
40 |
return qa_chain
|
41 |
|
42 |
+
llmchain = chain_pipeline()
|
43 |
|
44 |
def bot(query):
|
45 |
+
llm_response = llmchain.run({'query': query})
|
46 |
+
# Wrap the response in triple backticks for code formatting
|
47 |
+
formatted_response = f"```\n{llm_response}\n```"
|
48 |
+
return formatted_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 |
+
def respond(message, chat_history):
|
57 |
+
bot_message = bot(message)
|
58 |
+
chat_history.append((message, bot_message))
|
|
|
59 |
time.sleep(2)
|
60 |
+
return "", chat_history
|
61 |
+
|
62 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
63 |
|
64 |
+
demo.launch()
|