Spaces:
Runtime error
Runtime error
Srinivas T B
commited on
Commit
·
93f5eb7
1
Parent(s):
862499e
Upload 2 files
Browse files- app.py +66 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.llms import CTransformers
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
from langchain import PromptTemplate
|
| 4 |
+
import os
|
| 5 |
+
import io
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import time
|
| 8 |
+
|
| 9 |
+
custom_prompt_template = """
|
| 10 |
+
You are an AI coding assistant and your task is to resolve coding issues and return code snippets for the same based on the user's given query.
|
| 11 |
+
Query : {query}
|
| 12 |
+
You just return the helpful code and the 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 |
+
|
| 22 |
+
return prompt
|
| 23 |
+
|
| 24 |
+
def load_model():
|
| 25 |
+
llm = CTransformers(
|
| 26 |
+
model = 'codellama-7b-instruct.ggmlv3.Q4_0.bin',
|
| 27 |
+
model_type = 'llama',
|
| 28 |
+
max_new_tokens = 1096,
|
| 29 |
+
temperature = 0.2,
|
| 30 |
+
repetition_penalty = 1.13,
|
| 31 |
+
#gpu_layers = 3
|
| 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="Code Llama Srini") 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()
|
requirements.txt
ADDED
|
File without changes
|