Danielrahmai1991
commited on
Commit
•
64c17ae
1
Parent(s):
be8af02
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from langchain_community.llms import LlamaCpp
|
4 |
+
from langchain.prompts import PromptTemplate
|
5 |
+
from langchain.chains import LLMChain
|
6 |
+
from langchain_core.callbacks import StreamingStdOutCallbackHandler
|
7 |
+
|
8 |
+
|
9 |
+
callbacks = [StreamingStdOutCallbackHandler()]
|
10 |
+
print("creating ll started")
|
11 |
+
llm = LlamaCpp(
|
12 |
+
model_path="cerebras_Llama3-DocChat-1.0-8B_Base_adapt_basic_model_16bit.gguf",
|
13 |
+
temperature=0.75,
|
14 |
+
max_tokens=30,
|
15 |
+
top_p=4,
|
16 |
+
callback_manager=callbacks,
|
17 |
+
verbose=True, # Verbose is required to pass to the callback manager
|
18 |
+
)
|
19 |
+
print("creating ll ended")
|
20 |
+
|
21 |
+
template = """You are the Finiantial expert:
|
22 |
+
### Instruction:
|
23 |
+
{question}
|
24 |
+
### Input:
|
25 |
+
### Response:
|
26 |
+
"""
|
27 |
+
|
28 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
29 |
+
|
30 |
+
llm_chain_model = LLMChain(prompt=prompt, llm=llm)
|
31 |
+
print("creating model created")
|
32 |
+
|
33 |
+
|
34 |
+
def greet(question):
|
35 |
+
print(f"question is {question}")
|
36 |
+
|
37 |
+
out_gen = llm_chain_model.run(question)
|
38 |
+
print(f"out is {out_gen}")
|
39 |
+
return out_gen
|
40 |
+
|
41 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
42 |
+
demo.launch(debug=True, share=True)
|