Sahar7888 commited on
Commit
1e3a3f5
·
verified ·
1 Parent(s): 2219e63

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from langchain.callbacks.manager import CallbackManager
3
+ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
4
+ from langchain_community.llms import LlamaCpp
5
+ from pprint import pprint
6
+ import gradio as gr
7
+
8
+ # Initialize callback manager and LLM
9
+ callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
10
+
11
+ llm = LlamaCpp(
12
+ model_path="llama-2-7b-chat.Q5_K_M.gguf",
13
+ temperature=0.75,
14
+ max_tokens=2000,
15
+ top_p=1,
16
+ callback_manager=callback_manager,
17
+ verbose=True, # Verbose is required to pass to the callback manager
18
+ )
19
+
20
+ # Define the function to interact with the LLM
21
+ def llama_llm(prompt):
22
+ llama_prompt = f"<s>[INST]<<SYS>>\nEve lives in Hamburg.; Bob lives in Cape Town.; Alice lives in Mumbay.\n<</SYS>>\n{prompt}[/INST]"
23
+ response = llm(llama_prompt)
24
+ return response
25
+
26
+ # Create the Gradio interface
27
+ iface = gr.Interface(
28
+ fn=llama_llm,
29
+ inputs="text",
30
+ outputs="text",
31
+ title="Llama LLM Chat Interface",
32
+ description="Ask a question based on the system prompt: 'Eve lives in Hamburg.; Bob lives in Cape Town.; Alice lives in Mumbay.'"
33
+ )
34
+
35
+ # Launch the Gradio interface
36
+ iface.launch()