Gigishot commited on
Commit
fb946d7
·
verified ·
1 Parent(s): 178fabd

Rename blog.py to app.py

Browse files
Files changed (1) hide show
  1. blog.py → app.py +37 -37
blog.py → app.py RENAMED
@@ -1,37 +1,37 @@
1
- from flask import Flask, render_template, request
2
- from dotenv import load_dotenv
3
- from huggingface_hub import InferenceClient
4
- import os
5
-
6
- # Load environment variables
7
- load_dotenv()
8
-
9
- # Hugging Face Inference Client
10
- client = InferenceClient(api_key=os.getenv("TOKEN"))
11
-
12
- app = Flask(__name__)
13
-
14
- def generate_blog(paragraph_topic):
15
- response = client.chat.completions.create(
16
- model="HuggingFaceH4/zephyr-7b-beta",
17
- messages=[
18
- {
19
- "role": "user",
20
- "content": f"Write a paragraph about the following topic: {paragraph_topic}"
21
- }
22
- ],
23
- max_tokens=300, # prevent overly long text
24
- )
25
- return response.choices[0].message.content # ✅ fixed
26
-
27
- @app.route("/", methods=["GET", "POST"])
28
- def index():
29
- paragraph = ""
30
- if request.method == "POST":
31
- topic = request.form["topic"]
32
- paragraph = generate_blog(topic)
33
- return render_template("index.html", paragraph=paragraph)
34
-
35
- if __name__ == "__main__":
36
-
37
- app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
 
1
+ from flask import Flask, render_template, request
2
+ from dotenv import load_dotenv
3
+ from huggingface_hub import InferenceClient
4
+ import os
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+
9
+ # Hugging Face Inference Client
10
+ client = InferenceClient(api_key=os.getenv("TOKEN"))
11
+
12
+ app = Flask(__name__)
13
+
14
+ def generate_blog(paragraph_topic):
15
+ response = client.chat.completions.create(
16
+ model="HuggingFaceH4/zephyr-7b-beta",
17
+ messages=[
18
+ {
19
+ "role": "user",
20
+ "content": f"Write a paragraph about the following topic: {paragraph_topic}"
21
+ }
22
+ ],
23
+ max_tokens=300, # prevent overly long text
24
+ )
25
+ return response.choices[0].message.content # ✅ fixed
26
+
27
+ @app.route("/", methods=["GET", "POST"])
28
+ def index():
29
+ paragraph = ""
30
+ if request.method == "POST":
31
+ topic = request.form["topic"]
32
+ paragraph = generate_blog(topic)
33
+ return render_template("index.html", paragraph=paragraph)
34
+
35
+ if __name__ == "__main__":
36
+
37
+ app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))