Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,12 +15,17 @@ client = Groq(
|
|
| 15 |
|
| 16 |
def generate_blog(topic):
|
| 17 |
|
| 18 |
-
prompt = f"
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
print("API KEY EXISTS:", os.getenv("GROQ_API_KEY") is not None)
|
| 24 |
|
| 25 |
completion = client.chat.completions.create(
|
| 26 |
model="llama-3.1-8b-instant",
|
|
@@ -31,16 +36,20 @@ def generate_blog(topic):
|
|
| 31 |
}
|
| 32 |
],
|
| 33 |
temperature=0.7,
|
| 34 |
-
max_tokens=
|
| 35 |
)
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
return
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
|
| 43 |
-
print("
|
|
|
|
| 44 |
|
| 45 |
return f"Error: {str(e)}"
|
| 46 |
|
|
|
|
| 15 |
|
| 16 |
def generate_blog(topic):
|
| 17 |
|
| 18 |
+
prompt = f"""
|
| 19 |
+
Write a detailed blog article about: {topic}
|
| 20 |
|
| 21 |
+
Include:
|
| 22 |
+
1. Title
|
| 23 |
+
2. Introduction
|
| 24 |
+
3. Main Content
|
| 25 |
+
4. Conclusion
|
| 26 |
+
"""
|
| 27 |
|
| 28 |
+
try:
|
|
|
|
| 29 |
|
| 30 |
completion = client.chat.completions.create(
|
| 31 |
model="llama-3.1-8b-instant",
|
|
|
|
| 36 |
}
|
| 37 |
],
|
| 38 |
temperature=0.7,
|
| 39 |
+
max_tokens=700,
|
| 40 |
)
|
| 41 |
|
| 42 |
+
generated_text = completion.choices[0].message.content
|
| 43 |
+
|
| 44 |
+
print("GENERATED:")
|
| 45 |
+
print(generated_text)
|
| 46 |
|
| 47 |
+
return generated_text
|
| 48 |
|
| 49 |
except Exception as e:
|
| 50 |
|
| 51 |
+
print("ERROR:")
|
| 52 |
+
print(str(e))
|
| 53 |
|
| 54 |
return f"Error: {str(e)}"
|
| 55 |
|