Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import copy
|
| 4 |
-
import time
|
| 5 |
-
import llama_cpp
|
| 6 |
-
from llama_cpp import Llama
|
| 7 |
-
from huggingface_hub import hf_hub_download
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
llm = Llama(
|
| 11 |
-
model_path=hf_hub_download(
|
| 12 |
-
repo_id=os.environ.get("REPO_ID", "Severian/ANIMA-Phi-Neptune-Mistral-7B-gguf"),
|
| 13 |
-
filename=os.environ.get("MODEL_FILE", "ANIMA-Phi-Neptune-Mistral-7B-gguf"),
|
| 14 |
-
),
|
| 15 |
-
n_ctx=2048,
|
| 16 |
-
n_gpu_layers=50, # change n_gpu_layers if you have more or less VRAM
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
history = []
|
| 20 |
-
|
| 21 |
-
system_message = """
|
| 22 |
-
Your name is ANIMA, an Advanced Nature Inspired Multidisciplinary Assistant, and a leading expert "
|
| 23 |
-
"in biomimicry, biology, engineering, industrial design, environmental science, physiology, and paleontology. "
|
| 24 |
-
"Your goal is to help the user work in a step-by-step way through the Biomimicry Design Process to propose "
|
| 25 |
-
"biomimetic solutions to a challenge."
|
| 26 |
-
"Nature's Unifying Patterns:"
|
| 27 |
-
"Nature uses only the energy it needs and relies on freely available energy."
|
| 28 |
-
"Nature recycles all materials."
|
| 29 |
-
"Nature is resilient to disturbances."
|
| 30 |
-
"Nature tends to optimize rather than maximize."
|
| 31 |
-
"Nature provides mutual benefits."
|
| 32 |
-
"Nature runs on information."
|
| 33 |
-
"Nature uses chemistry and materials that are safe for living beings."
|
| 34 |
-
"Nature builds using abundant resources, incorporating rare resources only sparingly."
|
| 35 |
-
"Nature is locally attuned and responsive."
|
| 36 |
-
"Nature uses shape to determine functionality.
|
| 37 |
-
"""
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def generate_text(message, history):
|
| 41 |
-
temp = ""
|
| 42 |
-
input_prompt = f"[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n "
|
| 43 |
-
for interaction in history:
|
| 44 |
-
input_prompt = input_prompt + str(interaction[0]) + " [/INST] " + str(interaction[1]) + " </s><s> [INST] "
|
| 45 |
-
|
| 46 |
-
input_prompt = input_prompt + str(message) + " [/INST] "
|
| 47 |
-
|
| 48 |
-
output = llm(
|
| 49 |
-
input_prompt,
|
| 50 |
-
temperature=0.15,
|
| 51 |
-
top_p=0.1,
|
| 52 |
-
top_k=40,
|
| 53 |
-
repeat_penalty=1.1,
|
| 54 |
-
max_tokens=1024,
|
| 55 |
-
stop=[
|
| 56 |
-
"<|prompter|>",
|
| 57 |
-
"<|endoftext|>",
|
| 58 |
-
"<|endoftext|> \n",
|
| 59 |
-
"ASSISTANT:",
|
| 60 |
-
"USER:",
|
| 61 |
-
"SYSTEM:",
|
| 62 |
-
],
|
| 63 |
-
stream=True,
|
| 64 |
-
)
|
| 65 |
-
for out in output:
|
| 66 |
-
stream = copy.deepcopy(out)
|
| 67 |
-
temp += stream["choices"][0]["text"]
|
| 68 |
-
yield temp
|
| 69 |
-
|
| 70 |
-
history = ["init", input_prompt]
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
demo = gr.ChatInterface(
|
| 74 |
-
generate_text,
|
| 75 |
-
title="A N I M A",
|
| 76 |
-
description="ANIMA is an expert in various scientific disciplines.",
|
| 77 |
-
examples=["tell me everything about biomimicry"],
|
| 78 |
-
cache_examples=True,
|
| 79 |
-
retry_btn=None,
|
| 80 |
-
undo_btn="Delete Previous",
|
| 81 |
-
clear_btn="Clear",
|
| 82 |
-
)
|
| 83 |
-
demo.queue(concurrency_limit=10, max_size=5)
|
| 84 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|