Danielrahmai1991 commited on
Commit
4eeec68
1 Parent(s): 3f5c17a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -63
app.py CHANGED
@@ -1,13 +1,13 @@
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
- from langchain.retrievers import TFIDFRetriever
8
- from langchain.chains import RetrievalQA
9
- from langchain.memory import ConversationBufferMemory
10
- from langchain_community.chat_models import ChatLlamaCpp
11
 
12
 
13
  # callbacks = [StreamingStdOutCallbackHandler()]
@@ -30,73 +30,73 @@ from langchain_community.chat_models import ChatLlamaCpp
30
 
31
 
32
 
33
- def greet(question, model_type):
34
- print(f"question is {question}")
35
- out_gen = "testsetestestetsetsets"
36
- return out_gen
37
 
38
- demo = gr.Interface(fn=greet, inputs=["text", gr.Dropdown(
39
- ["With memory", "Without memory"], label="Memory status", info="With using memory, the output will be slow but strong"
40
- ),], outputs="text")
41
- demo.launch(debug=True, share=True)
42
 
43
 
44
- # import gradio as gr
45
 
46
- # from langchain_community.llms import LlamaCpp
47
- # from langchain.prompts import PromptTemplate
48
- # from langchain.chains import LLMChain
49
- # from langchain_core.callbacks import StreamingStdOutCallbackHandler
50
- # from langchain.retrievers import TFIDFRetriever
51
- # from langchain.chains import RetrievalQA
52
- # from langchain.memory import ConversationBufferMemory
53
- # from langchain_community.chat_models import ChatLlamaCpp
54
 
55
- # callbacks = [StreamingStdOutCallbackHandler()]
56
- # print("creating ll started")
57
- # M_NAME = "finbro-v0.1.0-llama-3-8B-instruct-1m.gguf"
58
- # llm = ChatLlamaCpp(
59
- # model_path=M_NAME,
60
- # n_batch=8,
61
- # temperature=0.85,
62
- # max_tokens=256,
63
- # top_p=0.95,
64
- # top_k = 10,
65
- # callback_manager=callbacks,
66
- # n_ctx=2048,
67
- # verbose=True, # Verbose is required to pass to the callback manager
68
- # )
69
- # # print("creating ll ended")
70
 
71
 
72
 
73
 
74
 
75
 
76
- # def greet(question, model_type):
77
- # print("prompt started ")
78
- # print(f"question is {question}")
79
- # template = """You are the Finiantial expert:
80
 
81
- # ### Instruction:
82
- # {question}
83
 
84
- # ### Input:
85
 
86
 
87
- # ### Response:
88
- # """
89
- # print("test1")
90
- # prompt = PromptTemplate(template=template, input_variables=["question"])
91
- # print("test2")
92
- # llm_chain_model = LLMChain(prompt=prompt, llm=llm)
93
- # print("test3")
94
- # out_gen = llm_chain_model.run(question)
95
- # print("test4")
96
- # print(f"out is: {out_gen}")
97
- # return out_gen
98
 
99
- # demo = gr.Interface(fn=greet, inputs=["text", gr.Dropdown(
100
- # ["Without memory", "With memory"], label="Memory status", info="With using memory, the output will be slow but strong"
101
- # ),], outputs="text")
102
- # demo.launch(debug=True, share=True)
 
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
+ # from langchain.retrievers import TFIDFRetriever
8
+ # from langchain.chains import RetrievalQA
9
+ # from langchain.memory import ConversationBufferMemory
10
+ # from langchain_community.chat_models import ChatLlamaCpp
11
 
12
 
13
  # callbacks = [StreamingStdOutCallbackHandler()]
 
30
 
31
 
32
 
33
+ # def greet(question, model_type):
34
+ # print(f"question is {question}")
35
+ # out_gen = "testsetestestetsetsets"
36
+ # return out_gen
37
 
38
+ # demo = gr.Interface(fn=greet, inputs=["text", gr.Dropdown(
39
+ # ["With memory", "Without memory"], label="Memory status", info="With using memory, the output will be slow but strong"
40
+ # ),], outputs="text")
41
+ # demo.launch(debug=True, share=True)
42
 
43
 
44
+ import gradio as gr
45
 
46
+ from langchain_community.llms import LlamaCpp
47
+ from langchain.prompts import PromptTemplate
48
+ from langchain.chains import LLMChain
49
+ from langchain_core.callbacks import StreamingStdOutCallbackHandler
50
+ from langchain.retrievers import TFIDFRetriever
51
+ from langchain.chains import RetrievalQA
52
+ from langchain.memory import ConversationBufferMemory
53
+ from langchain_community.chat_models import ChatLlamaCpp
54
 
55
+ callbacks = [StreamingStdOutCallbackHandler()]
56
+ print("creating ll started")
57
+ M_NAME = "finbro-v0.1.0-llama-3-8B-instruct-1m.gguf"
58
+ llm = ChatLlamaCpp(
59
+ model_path=M_NAME,
60
+ n_batch=8,
61
+ temperature=0.85,
62
+ max_tokens=256,
63
+ top_p=0.95,
64
+ top_k = 10,
65
+ callback_manager=callbacks,
66
+ n_ctx=2048,
67
+ verbose=True, # Verbose is required to pass to the callback manager
68
+ )
69
+ # print("creating ll ended")
70
 
71
 
72
 
73
 
74
 
75
 
76
+ def greet(question, model_type):
77
+ print("prompt started ")
78
+ print(f"question is {question}")
79
+ template = """You are the Finiantial expert:
80
 
81
+ ### Instruction:
82
+ {question}
83
 
84
+ ### Input:
85
 
86
 
87
+ ### Response:
88
+ """
89
+ print("test1")
90
+ prompt = PromptTemplate(template=template, input_variables=["question"])
91
+ print("test2")
92
+ llm_chain_model = LLMChain(prompt=prompt, llm=llm)
93
+ print("test3")
94
+ out_gen = llm_chain_model.run(question)
95
+ print("test4")
96
+ print(f"out is: {out_gen}")
97
+ return out_gen
98
 
99
+ demo = gr.Interface(fn=greet, inputs=["text", gr.Dropdown(
100
+ ["Without memory", "With memory"], label="Memory status", info="With using memory, the output will be slow but strong"
101
+ ),], outputs="text")
102
+ demo.launch(debug=True, share=True)