BlinkDL commited on
Commit
f714b01
1 Parent(s): 9fd6cde

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os, gc, torch
3
+ from datetime import datetime
4
+ from huggingface_hub import hf_hub_download
5
+ from pynvml import *
6
+ nvmlInit()
7
+ gpu_h = nvmlDeviceGetHandleByIndex(0)
8
+ ctx_limit = 1024
9
+
10
+ def generate_prompt(instruction, input=None):
11
+ if input:
12
+ return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
13
+
14
+ # Instruction:
15
+ {instruction}
16
+
17
+ # Input:
18
+ {input}
19
+
20
+ # Response:
21
+ """
22
+ else:
23
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
24
+
25
+ # Instruction:
26
+ {instruction}
27
+
28
+ # Response:
29
+ """
30
+
31
+ def evaluate(
32
+ instruction,
33
+ input=None,
34
+ temperature=1.0,
35
+ top_p=0.75,
36
+ max_new_tokens=200,
37
+ **kwargs,
38
+ ):
39
+ prompt = generate_prompt(instruction, input)
40
+ return prompt
41
+
42
+ g = gr.Interface(
43
+ fn=evaluate,
44
+ inputs=[
45
+ gr.components.Textbox(
46
+ lines=2, label="Instruction", placeholder="Tell me about alpacas."
47
+ ),
48
+ gr.components.Textbox(lines=2, label="Input", placeholder="none"),
49
+ gr.components.Slider(minimum=0, maximum=1, value=1.0, label="Temperature"),
50
+ gr.components.Slider(minimum=0, maximum=1, value=0.75, label="Top p"),
51
+ gr.components.Slider(
52
+ minimum=1, maximum=256, step=1, value=200, label="Max tokens"
53
+ ),
54
+ ],
55
+ outputs=[
56
+ gr.inputs.Textbox(
57
+ lines=5,
58
+ label="Output",
59
+ )
60
+ ],
61
+ title="🐦Raven-RWKV 7B",
62
+ description="Raven-RWKV 7B is [RWKV 7B](https://github.com/BlinkDL/ChatRWKV) finetuned to follow instructions. It is trained on the [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) dataset and more.",
63
+ )
64
+ g.queue(concurrency_count=1, max_size=10)
65
+ g.launch(share=False)