rajivmehtapy commited on
Commit
eefe540
1 Parent(s): b5d9a88

update in code.

Browse files
Files changed (2) hide show
  1. app.py +28 -2
  2. models/Phi-3-mini-4k-instruct-q4.gguf +1 -0
app.py CHANGED
@@ -1,7 +1,11 @@
1
  import gradio as gr
2
  import os
3
  from loguru import logger
4
-
 
 
 
 
5
  # Create a directory for logs if it doesn't exist
6
  if not os.path.exists('logs'):
7
  os.makedirs('logs')
@@ -12,9 +16,31 @@ log_file = 'logs/file_{time}.log'
12
  # Configure the logger to write to the log file
13
  logger.add(log_file, rotation="500 MB")
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def greet(name):
16
  logger.info("This is an info message")
17
- return "Hi , " + name + "!!"
 
 
18
 
19
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
20
  demo.launch()
 
1
  import gradio as gr
2
  import os
3
  from loguru import logger
4
+ from langchain_community.llms import LlamaCpp
5
+ from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler
6
+ from langchain_core.prompts import PromptTemplate
7
+ import spaces
8
+ import json
9
  # Create a directory for logs if it doesn't exist
10
  if not os.path.exists('logs'):
11
  os.makedirs('logs')
 
16
  # Configure the logger to write to the log file
17
  logger.add(log_file, rotation="500 MB")
18
 
19
+ template = """Question: {question}
20
+
21
+ Answer: Let's work this out in a step by step way to be sure we have the right answer."""
22
+
23
+ prompt = PromptTemplate.from_template(template)
24
+ # Callbacks support token-wise streaming
25
+ callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
26
+
27
+ # n_gpu_layers = -1 # The number of layers to put on the GPU. The rest will be on the CPU. If you don't know how many layers there are, you can use -1 to move all to GPU.
28
+ # n_batch = 512 # Should be between 1 and n_ctx, consider the amount of VRAM in your GPU.
29
+
30
+ # Make sure the model path is correct for your system!
31
+ llm = LlamaCpp(
32
+ model_path="/home/user/app/models/Phi-3-mini-4k-instruct-q4.gguf",
33
+ callback_manager=callback_manager,
34
+ verbose=True, # Verbose is required to pass to the callback manager
35
+ )
36
+ llm_chain = prompt | llm
37
+
38
+ @spaces.GPU(duration=120)
39
  def greet(name):
40
  logger.info("This is an info message")
41
+ question = name
42
+ # print(llm_chain.invoke({"question": question}))
43
+ return llm_chain.invoke({"question": question})
44
 
45
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
46
  demo.launch()
models/Phi-3-mini-4k-instruct-q4.gguf ADDED
@@ -0,0 +1 @@
 
 
1
+ ../../.cache/huggingface/hub/models--microsoft--Phi-3-mini-4k-instruct-gguf/blobs/8a83c7fb9049a9b2e92266fa7ad04933bb53aa1e85136b7b30f1b8000ff2edef