Spaces:
Sleeping
Sleeping
Pooja P
commited on
Commit
Β·
99d207a
1
Parent(s):
dfc4278
used transformer instead of openai
Browse files
app.py
CHANGED
@@ -6,21 +6,39 @@
|
|
6 |
# return generator(f"Write a blog on: {topic}", max_length=200)[0]["generated_text"]
|
7 |
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
from transformers import pipeline
|
10 |
import gradio as gr
|
11 |
|
12 |
-
# Load the model
|
13 |
generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Text Generator with GPT-2")
|
24 |
|
25 |
-
|
26 |
-
iface.launch()
|
|
|
6 |
# return generator(f"Write a blog on: {topic}", max_length=200)[0]["generated_text"]
|
7 |
|
8 |
|
9 |
+
# from transformers import pipeline
|
10 |
+
# import gradio as gr
|
11 |
+
|
12 |
+
# # Load the model
|
13 |
+
# generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
|
14 |
+
|
15 |
+
# # Define your function
|
16 |
+
# def generate_text(prompt):
|
17 |
+
# result = generator(prompt, max_length=100, num_return_sequences=1, do_sample=True,
|
18 |
+
# temperature=0.7,
|
19 |
+
# top_p=0.9,)
|
20 |
+
# return result[0]["generated_text"]
|
21 |
+
|
22 |
+
# # Create Gradio interface
|
23 |
+
# iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Text Generator with GPT-2")
|
24 |
+
|
25 |
+
# # β
This line is required to actually launch the app on Hugging Face Spaces
|
26 |
+
# iface.launch()
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
from transformers import pipeline
|
31 |
import gradio as gr
|
32 |
|
|
|
33 |
generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
|
34 |
|
35 |
+
def generate_blog(topic):
|
36 |
+
prompt = f"""
|
37 |
+
Write a detailed and engaging blog post about "{topic}".
|
38 |
+
Include an introduction, 2β3 subheadings with paragraphs, and a conclusion.
|
39 |
+
Make it informative and conversational.
|
40 |
+
"""
|
41 |
+
result = generator(prompt, max_length=700, do_sample=True, temperature=0.7, top_p=0.9)
|
42 |
+
return result[0]['generated_text']
|
|
|
43 |
|
44 |
+
gr.Interface(fn=generate_blog, inputs="text", outputs="text", title="AI Blog Writer").launch()
|
|