Marcus Posey commited on
Commit
109f4c0
·
1 Parent(s): 7fa4251

Add gradio UI

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from vllm import LLM, SamplingParams
2
+ import gradio as gr
3
+ import os
4
+ from huggingface_hub import login
5
+
6
+
7
+ class TextCompletion:
8
+ def __init__(self, model, sampling_params):
9
+ self.model = model
10
+ self.sampling_params = sampling_params
11
+
12
+ def generate(self, prompt: str):
13
+ output = self.model.generate(prompt, self.sampling_params)
14
+ response = output[0].outputs[0].text
15
+ return response
16
+
17
+
18
+ if __name__ == "__main__":
19
+ HF_TOKEN = os.getenv('HF_TOKEN')
20
+ login(token=HF_TOKEN)
21
+
22
+ model = LLM(
23
+ model="mep296/llama-3-8b-entigraph-quality",
24
+ tokenizer="meta-llama/Meta-Llama-3-8B",
25
+ device="cuda"
26
+ )
27
+ tokenizer = model.get_tokenizer()
28
+ sampling_params = SamplingParams(
29
+ temperature=0.1,
30
+ max_tokens=500,
31
+ stop=[tokenizer.eos_token, "## Example 7", "##"]
32
+ )
33
+
34
+ def text_completion_fn(prompt):
35
+ text_completer = TextCompletion(model, sampling_params)
36
+ return text_completer.generate(prompt)
37
+ demo = gr.Interface(fn=text_completion_fn, inputs="textbox", outputs="textbox")
38
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.44.0
2
+ vllm==0.5.3.post1