imperialwool commited on
Commit
1de5e4f
1 Parent(s): 2c2e98e

Update gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +5 -2
gradio_app.py CHANGED
@@ -1,5 +1,6 @@
1
  # Importing libraries
2
  from llama_cpp import Llama
 
3
  import gradio as gr
4
  import psutil
5
 
@@ -30,6 +31,7 @@ with open('system.message', 'r', encoding='utf-8') as f:
30
  system_message = f.read()
31
 
32
  def generate_answer(request: str, max_tokens: int = 256, custom_prompt: str = None):
 
33
  logs = f"Request: {request}\nMax tokens: {max_tokens}\nCustom prompt: {custom_prompt}\n"
34
  try:
35
  maxTokens = max_tokens if 16 <= max_tokens <= 256 else 64
@@ -58,11 +60,12 @@ def generate_answer(request: str, max_tokens: int = 256, custom_prompt: str = No
58
  text = "Sorry, but something went wrong while generating answer. Try again or fix code. If you are maintainer of this space, look into logs."
59
 
60
  logs += f"\nFinal: '''{text}'''"
 
61
  return text, logs
62
  except Exception as e:
63
- print(e)
 
64
  return "Oops! Internal server error. Check the logs of space/instance.", logs
65
- print("\n\n\n")
66
 
67
  print("! LOAD GRADIO INTERFACE !")
68
  demo = gr.Interface(
 
1
  # Importing libraries
2
  from llama_cpp import Llama
3
+ from time import time
4
  import gradio as gr
5
  import psutil
6
 
 
31
  system_message = f.read()
32
 
33
  def generate_answer(request: str, max_tokens: int = 256, custom_prompt: str = None):
34
+ t0 = time()
35
  logs = f"Request: {request}\nMax tokens: {max_tokens}\nCustom prompt: {custom_prompt}\n"
36
  try:
37
  maxTokens = max_tokens if 16 <= max_tokens <= 256 else 64
 
60
  text = "Sorry, but something went wrong while generating answer. Try again or fix code. If you are maintainer of this space, look into logs."
61
 
62
  logs += f"\nFinal: '''{text}'''"
63
+ logs += f"\n\nTime spent: {time()-t0}"
64
  return text, logs
65
  except Exception as e:
66
+ logs += str(e)
67
+ logs += f"\n\nTime spent: {time()-t0}"
68
  return "Oops! Internal server error. Check the logs of space/instance.", logs
 
69
 
70
  print("! LOAD GRADIO INTERFACE !")
71
  demo = gr.Interface(