Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,22 +7,28 @@ import os
|
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
# Hugging Face Inference Client
|
| 10 |
-
client = InferenceClient(
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
app = Flask(__name__)
|
| 13 |
|
| 14 |
def generate_blog(paragraph_topic):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
@app.route("/", methods=["GET", "POST"])
|
| 28 |
def index():
|
|
@@ -33,5 +39,4 @@ def index():
|
|
| 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)))
|
|
|
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
# Hugging Face Inference Client
|
| 10 |
+
client = InferenceClient(
|
| 11 |
+
provider="groq",
|
| 12 |
+
api_key=os.getenv("HF_API_KEY")
|
| 13 |
+
)
|
| 14 |
|
| 15 |
app = Flask(__name__)
|
| 16 |
|
| 17 |
def generate_blog(paragraph_topic):
|
| 18 |
+
try:
|
| 19 |
+
response = client.chat.completions.create(
|
| 20 |
+
model="meta-llama/Llama-3.1-8B-Instruct",
|
| 21 |
+
messages=[
|
| 22 |
+
{
|
| 23 |
+
"role": "user",
|
| 24 |
+
"content": f"Write a blog paragraph about: {paragraph_topic}"
|
| 25 |
+
}
|
| 26 |
+
],
|
| 27 |
+
max_tokens=300,
|
| 28 |
+
)
|
| 29 |
+
return response.choices[0].message.content
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Error generating blog: {str(e)}"
|
| 32 |
|
| 33 |
@app.route("/", methods=["GET", "POST"])
|
| 34 |
def index():
|
|
|
|
| 39 |
return render_template("index.html", paragraph=paragraph)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
+
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|
|
|