Spaces:
Runtime error
Runtime error
kirp
commited on
Commit
·
86acf2f
1
Parent(s):
710ee23
stream output
Browse files
app.py
CHANGED
|
@@ -1,11 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import copy
|
| 4 |
-
import random
|
| 5 |
-
import os
|
| 6 |
-
import requests
|
| 7 |
-
import time
|
| 8 |
-
import sys
|
| 9 |
|
| 10 |
from huggingface_hub import snapshot_download
|
| 11 |
from llama_cpp import Llama
|
|
@@ -31,29 +25,31 @@ def generate(
|
|
| 31 |
top_k=40,
|
| 32 |
max_tokens=512,
|
| 33 |
):
|
|
|
|
| 34 |
prompt = template.format(input)
|
| 35 |
-
output =
|
|
|
|
| 36 |
temperature = temperature,
|
| 37 |
top_k = top_k,
|
| 38 |
top_p = top_p,
|
| 39 |
max_tokens = max_tokens,
|
| 40 |
stop=["<|im_end|>"],
|
| 41 |
-
echo=
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
g = gr.Interface(
|
| 46 |
fn=generate,
|
| 47 |
inputs=[
|
| 48 |
gr.components.Textbox(
|
| 49 |
-
lines=2, label="Prompt", value = "What is
|
| 50 |
),
|
| 51 |
gr.components.Slider(minimum=0, maximum=1, value=0.1, label="Temperature"),
|
| 52 |
gr.components.Slider(minimum=0, maximum=1, value=1, label="Top p"),
|
| 53 |
gr.components.Slider(minimum=0, maximum=100, step=1, value=50, label="Top k"),
|
| 54 |
-
gr.components.Slider(
|
| 55 |
-
minimum=1, maximum=1024, step=1, value=128, label="Max tokens"
|
| 56 |
-
),
|
| 57 |
],
|
| 58 |
outputs=[
|
| 59 |
gr.Textbox(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
from huggingface_hub import snapshot_download
|
| 5 |
from llama_cpp import Llama
|
|
|
|
| 25 |
top_k=40,
|
| 26 |
max_tokens=512,
|
| 27 |
):
|
| 28 |
+
|
| 29 |
prompt = template.format(input)
|
| 30 |
+
output = ""
|
| 31 |
+
for chunk in model.create_completion(prompt,
|
| 32 |
temperature = temperature,
|
| 33 |
top_k = top_k,
|
| 34 |
top_p = top_p,
|
| 35 |
max_tokens = max_tokens,
|
| 36 |
stop=["<|im_end|>"],
|
| 37 |
+
echo = False,
|
| 38 |
+
stream = True):
|
| 39 |
+
output +=chunk["choices"][0]["text"]
|
| 40 |
+
yield output
|
| 41 |
+
return output
|
| 42 |
|
| 43 |
g = gr.Interface(
|
| 44 |
fn=generate,
|
| 45 |
inputs=[
|
| 46 |
gr.components.Textbox(
|
| 47 |
+
lines=2, label="Prompt", value = "What is Huggingface?"
|
| 48 |
),
|
| 49 |
gr.components.Slider(minimum=0, maximum=1, value=0.1, label="Temperature"),
|
| 50 |
gr.components.Slider(minimum=0, maximum=1, value=1, label="Top p"),
|
| 51 |
gr.components.Slider(minimum=0, maximum=100, step=1, value=50, label="Top k"),
|
| 52 |
+
gr.components.Slider(minimum=1, maximum=1024, step=1, value=256, label="Max tokens"),
|
|
|
|
|
|
|
| 53 |
],
|
| 54 |
outputs=[
|
| 55 |
gr.Textbox(
|