tommy24 commited on
Commit
a35163f
·
1 Parent(s): 93aea48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -24
app.py CHANGED
@@ -1,45 +1,75 @@
1
- import gradio as gr
2
- from langchain.llms import LlamaCpp
3
- from langchain import PromptTemplate, LLMChain
4
- from langchain.llms import GPT4All
5
- from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
6
 
7
 
8
- # import requests
9
 
10
- # url = "https://huggingface.co/TheBloke/Nous-Hermes-13B-GGML/resolve/main/nous-hermes-13b.ggmlv3.q4_0.bin"
11
 
12
- # response = requests.get(url)
13
 
14
- # with open("nous-hermes-13b.ggmlv3.q4_0.bin", "wb") as f:
15
- # f.write(response.content)
16
 
17
 
18
- print("DONE")
19
 
20
- def func(user):
21
 
22
- template = """Question: {question}
 
 
23
 
24
- Answer: Let's think step by step."""
25
 
26
- prompt = PromptTemplate(template=template, input_variables=["question"])
 
 
 
 
 
27
 
28
- local_path = (
29
- "./nous-hermes-13b.ggmlv3.q4_0.bin"
30
- )
 
 
 
 
 
 
 
 
 
 
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- # # Callbacks support token-wise streaming
34
- # callbacks = [StreamingStdOutCallbackHandler()]
35
 
36
- # Verbose is required to pass to the callback manager
37
- llm = LlamaCpp(model_path="./nous-hermes-13b.ggmlv3.q4_0.bin", n_ctx=2048)
38
- llm_chain = LLMChain(prompt=prompt, llm=llm)
39
  question = user
40
  llm_chain.run(question)
41
 
42
  return llm_chain.run(question)
43
 
44
  iface = gr.Interface(fn=func, inputs="text", outputs="text")
45
- iface.launch()
 
1
+ # import gradio as gr
2
+ # from langchain.llms import LlamaCpp
3
+ # from langchain import PromptTemplate, LLMChain
4
+ # from langchain.llms import GPT4All
5
+ # from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
6
 
7
 
8
+ # # import requests
9
 
10
+ # # url = "https://huggingface.co/TheBloke/Nous-Hermes-13B-GGML/resolve/main/nous-hermes-13b.ggmlv3.q4_0.bin"
11
 
12
+ # # response = requests.get(url)
13
 
14
+ # # with open("nous-hermes-13b.ggmlv3.q4_0.bin", "wb") as f:
15
+ # # f.write(response.content)
16
 
17
 
18
+ # print("DONE")
19
 
20
+ # def func(user):
21
 
22
+ # template = """
23
+ # Your name is John and not a assistant but more like a chatbot. Respond precise not more words and act like a human. for example: user: How are you? You: I'm doing good how about you?. user: hello You: Hello how you doing?. Don't say How can I assist you today?.
24
+ # Question: {question}
25
 
26
+ # Answer: """
27
 
28
+ # prompt = PromptTemplate(template=template, input_variables=["question"])
29
+
30
+ # local_path = (
31
+ # "./nous-hermes-13b.ggmlv3.q4_0.bin"
32
+ # )
33
+
34
 
35
+ # # # Callbacks support token-wise streaming
36
+ # # callbacks = [StreamingStdOutCallbackHandler()]
37
+
38
+ # # Verbose is required to pass to the callback manager
39
+ # llm = LlamaCpp(model_path="./nous-hermes-13b.ggmlv3.q4_0.bin", n_ctx=2048)
40
+ # llm_chain = LLMChain(prompt=prompt, llm=llm)
41
+ # question = user
42
+ # llm_chain.run(question)
43
+
44
+ # return llm_chain.run(question)
45
+
46
+ # iface = gr.Interface(fn=func, inputs="text", outputs="text")
47
+ # iface.launch()
48
 
49
+ import gradio as gr
50
+ from langchain.llms import LlamaCpp
51
+ from langchain import PromptTemplate, LLMChain
52
+ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
53
+
54
+ print("DONE")
55
+
56
+ def func(user):
57
+ template = """
58
+ Your name is John and not a assistant but more like a chatbot. Respond precise not more words and act like a human. for example: user: How are you? You: I'm doing good how about you?. user: hello You: Hello how you doing?. Don't say How can I assist you today?.
59
+ Question: {question}
60
+
61
+ Answer: """
62
+
63
+ prompt = PromptTemplate(template=template, input_variables=["question"])
64
 
65
+ local_path = "./nous-hermes-13b.ggmlv3.q4_0.bin"
 
66
 
67
+ llm = LlamaCpp(model_path=local_path, n_ctx=2048)
68
+ llm_chain = LLMChain(prompt=prompt, llm=llm, streaming=True) # Enable streaming mode
 
69
  question = user
70
  llm_chain.run(question)
71
 
72
  return llm_chain.run(question)
73
 
74
  iface = gr.Interface(fn=func, inputs="text", outputs="text")
75
+ iface.launch()