Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from ctransformers import AutoModelForCausalLM
|
|
|
2 |
from fastapi import FastAPI, Form
|
3 |
from pydantic import BaseModel
|
4 |
|
@@ -17,7 +18,7 @@ class validation(BaseModel):
|
|
17 |
#Fast API
|
18 |
app = FastAPI()
|
19 |
|
20 |
-
|
21 |
@app.post("/llm_on_cpu")
|
22 |
async def stream(item: validation):
|
23 |
system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request. Write only in ITALIAN.'
|
@@ -25,3 +26,45 @@ async def stream(item: validation):
|
|
25 |
user, assistant = "<|user|>", "<|assistant|>"
|
26 |
prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
|
27 |
return llm(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from ctransformers import AutoModelForCausalLM
|
2 |
+
import gradio as gr
|
3 |
from fastapi import FastAPI, Form
|
4 |
from pydantic import BaseModel
|
5 |
|
|
|
18 |
#Fast API
|
19 |
app = FastAPI()
|
20 |
|
21 |
+
|
22 |
@app.post("/llm_on_cpu")
|
23 |
async def stream(item: validation):
|
24 |
system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request. Write only in ITALIAN.'
|
|
|
26 |
user, assistant = "<|user|>", "<|assistant|>"
|
27 |
prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
|
28 |
return llm(prompt)
|
29 |
+
|
30 |
+
|
31 |
+
greety = """
|
32 |
+
Test
|
33 |
+
"""
|
34 |
+
|
35 |
+
|
36 |
+
css = """
|
37 |
+
h1 {
|
38 |
+
text-align: center;
|
39 |
+
}
|
40 |
+
#duplicate-button {
|
41 |
+
margin: auto;
|
42 |
+
color: white;
|
43 |
+
background: #1565c0;
|
44 |
+
border-radius: 100vh;
|
45 |
+
}
|
46 |
+
.contain {
|
47 |
+
max-width: 900px;
|
48 |
+
margin: auto;
|
49 |
+
padding-top: 1.5rem;
|
50 |
+
}
|
51 |
+
"""
|
52 |
+
|
53 |
+
chat_interface = gr.ChatInterface(
|
54 |
+
fn=stream,
|
55 |
+
stop_btn=None,
|
56 |
+
examples=[
|
57 |
+
["explain Large language model"],
|
58 |
+
["what is quantum computing"]
|
59 |
+
],
|
60 |
+
)
|
61 |
+
|
62 |
+
with gr.Blocks(css=css) as demo:
|
63 |
+
gr.HTML("<h1><center>LLM Deployment Space<h1><center>")
|
64 |
+
gr.HTML("<h3><center><a href='#'>AI</a>💬<h3><center>")
|
65 |
+
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
66 |
+
chat_interface.render()
|
67 |
+
gr.Markdown(greety)
|
68 |
+
|
69 |
+
if __name__ == "__main__":
|
70 |
+
demo.queue(max_size=10).launch()
|