aburnazyan
commited on
Commit
•
68343c9
1
Parent(s):
9024ddf
ui controls and reqs
Browse files- app.py +28 -1
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,3 +1,30 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
+
model_name = "aburnazy/opt-350m-hy-wiki-alpaca"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def generate_text(prompt, temperature, top_k, top_p, max_length):
|
9 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
10 |
+
outputs = model.generate(inputs, max_length=max_length, temperature=temperature, top_k=top_k, top_p=top_p, do_sample=True)
|
11 |
+
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
+
return text
|
13 |
+
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=generate_text,
|
16 |
+
inputs=[
|
17 |
+
gr.inputs.Textbox(lines=2, placeholder=f"""### Instruction:
|
18 |
+
Ո՞րն է Հայաստանի մայրաքաղաքը
|
19 |
+
### Response:
|
20 |
+
|
21 |
+
"""),
|
22 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.01, default=0.1, label='Temperature'),
|
23 |
+
gr.inputs.Slider(minimum=0, maximum=100, step=1, default=20, label='Top K'),
|
24 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.01, default=0.1, label='Top P'),
|
25 |
+
gr.inputs.Slider(minimum=10, maximum=1024, step=1, default=512, label='Max Length'),
|
26 |
+
],
|
27 |
+
outputs="text"
|
28 |
+
)
|
29 |
+
|
30 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|