Spaces:
Paused
Paused
Commit
·
440d166
1
Parent(s):
ac2329a
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import transformers as t
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load your fine-tuned model and tokenizer
|
6 |
+
model = t.AutoModelForCausalLM.from_pretrained("./weights")
|
7 |
+
tokenizer = t.AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-hf")
|
8 |
+
tokenizer.pad_token_id = 0
|
9 |
+
|
10 |
+
# Define a prediction function
|
11 |
+
def generate_article(title):
|
12 |
+
prompt = f"Below is a title for an article. Write an article that appropriately suits the title: \n\n### Title:\n{title}\n\n### Article:\n"
|
13 |
+
pipe = t.pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=1000)
|
14 |
+
output = pipe([prompt])
|
15 |
+
generated_article = output[0][0]["generated_text"]
|
16 |
+
return generated_article
|
17 |
+
|
18 |
+
# Create a Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=generate_article,
|
21 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Article Title Here"),
|
22 |
+
outputs="text",
|
23 |
+
title="Article Generator",
|
24 |
+
description="Enter a title to generate an article."
|
25 |
+
)
|
26 |
+
|
27 |
+
# Launch the app
|
28 |
+
iface.launch()
|