Marcus Posey commited on
Commit ·
0a025aa
1
Parent(s): 17bb9ca
Add application file
Browse files- app.py +32 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from vllm import LLM, SamplingParams
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class TextCompletion:
|
| 6 |
+
def __init__(self, model, sampling_params):
|
| 7 |
+
self.model = model
|
| 8 |
+
self.sampling_params = sampling_params
|
| 9 |
+
|
| 10 |
+
def generate(self, prompt: str):
|
| 11 |
+
output = self.model.generate(prompt, self.sampling_params)
|
| 12 |
+
response = output[0].outputs[0].text
|
| 13 |
+
return response
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
if __name__ == "__main__":
|
| 17 |
+
model = LLM(
|
| 18 |
+
model="mep296/llama-3-8b-rephrase-quality",
|
| 19 |
+
tokenizer="meta-llama/Meta-Llama-3-8B",
|
| 20 |
+
device="cuda"
|
| 21 |
+
)
|
| 22 |
+
sampling_params = SamplingParams(
|
| 23 |
+
temperature=0.1,
|
| 24 |
+
max_tokens=500,
|
| 25 |
+
stop=[tokenizer.eos_token, "## Example 7", "##"]
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
def text_completion_fn(prompt):
|
| 29 |
+
text_completer = TextCompletion(model, sampling_params)
|
| 30 |
+
return text_completer.generate(prompt)
|
| 31 |
+
demo = gr.Interface(fn=text_completion_fn, inputs="textbox", outputs="textbox")
|
| 32 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.0
|
| 2 |
+
vllm==0.5.3.post1
|