Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline
|
2 |
+
from gradio import Interface
|
3 |
+
|
4 |
+
model_name = "Hadeel11/fine-tuned-model-2"
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
|
10 |
+
model.half()
|
11 |
+
|
12 |
+
text_generator = TextGenerationPipeline(model=model, tokenizer=tokenizer)
|
13 |
+
|
14 |
+
def generate_text(prompt):
|
15 |
+
return text_generator(prompt, max_length=512, num_return_sequences=1)[0]['generated_text']
|
16 |
+
|
17 |
+
iface = Interface(fn=generate_text, inputs="text", outputs="text", title="Text Generation Inference")
|
18 |
+
|
19 |
+
iface.launch()
|