Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,28 +3,21 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
3 |
import torch
|
4 |
from dotenv import load_dotenv
|
5 |
import os
|
|
|
|
|
6 |
load_dotenv()
|
7 |
|
8 |
-
#
|
9 |
-
#model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-4k-instruct", trust_remote_code=True)
|
10 |
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
|
11 |
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b")
|
12 |
-
#hf_token=os.getenv("HF_TOKEN")
|
13 |
|
14 |
-
# Load the model and tokenizer
|
15 |
-
#model_name = "openai-community/gpt2"
|
16 |
-
#tokenizer = AutoTokenizer.from_pretrained(model_name)
|
17 |
-
#model = AutoModelForCausalLM.from_pretrained(model_name,token=hf_token)
|
18 |
|
19 |
# Function to generate blog content
|
20 |
def generate_blog(topic, keywords):
|
21 |
prompt_template = f"""
|
22 |
You are a technical content writer. Write a detailed and informative blog on the following topic.
|
23 |
-
|
24 |
Topic: {topic}
|
25 |
-
|
26 |
Keywords: {keywords}
|
27 |
-
|
28 |
Make sure the blog covers the following sections:
|
29 |
1. Introduction
|
30 |
2. Detailed Explanation
|
@@ -33,10 +26,9 @@ def generate_blog(topic, keywords):
|
|
33 |
|
34 |
Blog:
|
35 |
"""
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
blog_content = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
40 |
|
41 |
return blog_content
|
42 |
|
@@ -53,4 +45,4 @@ iface = gr.Interface(
|
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
-
iface.launch()
|
|
|
3 |
import torch
|
4 |
from dotenv import load_dotenv
|
5 |
import os
|
6 |
+
|
7 |
+
# Load environment variables
|
8 |
load_dotenv()
|
9 |
|
10 |
+
# Load the model and tokenizer
|
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
|
12 |
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b")
|
|
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Function to generate blog content
|
16 |
def generate_blog(topic, keywords):
|
17 |
prompt_template = f"""
|
18 |
You are a technical content writer. Write a detailed and informative blog on the following topic.
|
|
|
19 |
Topic: {topic}
|
|
|
20 |
Keywords: {keywords}
|
|
|
21 |
Make sure the blog covers the following sections:
|
22 |
1. Introduction
|
23 |
2. Detailed Explanation
|
|
|
26 |
|
27 |
Blog:
|
28 |
"""
|
29 |
+
input_ids = tokenizer(prompt_template, return_tensors="pt")
|
30 |
+
outputs = model.generate(**input_ids)
|
31 |
+
blog_content = tokenizer.decode(outputs[0])
|
|
|
32 |
|
33 |
return blog_content
|
34 |
|
|
|
45 |
)
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
+
iface.launch(share=True) # Set share=True to generate a public link
|