Spaces:
Sleeping
Sleeping
Switch to Groq API with llama-3.1-8b-instant
Browse files- app.py +14 -14
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,36 +1,36 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
-
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Recipe Generator", layout="centered")
|
| 6 |
|
| 7 |
st.title("🍳 AI Recipe Generator")
|
| 8 |
st.write("Enter ingredients and get a recipe suggestion!")
|
| 9 |
|
| 10 |
-
@st.cache_resource
|
| 11 |
-
def get_client():
|
| 12 |
-
token = os.environ.get("HF_TOKEN")
|
| 13 |
-
return InferenceClient(provider="together", token=token)
|
| 14 |
-
|
| 15 |
-
client = get_client()
|
| 16 |
-
|
| 17 |
ingredients = st.text_input("Enter ingredients (comma-separated):", placeholder="eggs, cheese, spinach")
|
| 18 |
|
| 19 |
if st.button("Generate Recipe"):
|
| 20 |
if ingredients:
|
| 21 |
with st.spinner("Generating recipe..."):
|
|
|
|
| 22 |
prompt = (
|
| 23 |
f"Write a complete recipe using these ingredients: {ingredients}. "
|
| 24 |
"Include: a creative recipe name, ingredients with amounts, "
|
| 25 |
"numbered cooking steps, and estimated cooking time."
|
| 26 |
)
|
| 27 |
-
response =
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
-
|
|
|
|
| 34 |
st.success(recipe)
|
| 35 |
else:
|
| 36 |
st.warning("Please enter some ingredients!")
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
import streamlit as st
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Recipe Generator", layout="centered")
|
| 6 |
|
| 7 |
st.title("🍳 AI Recipe Generator")
|
| 8 |
st.write("Enter ingredients and get a recipe suggestion!")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
ingredients = st.text_input("Enter ingredients (comma-separated):", placeholder="eggs, cheese, spinach")
|
| 11 |
|
| 12 |
if st.button("Generate Recipe"):
|
| 13 |
if ingredients:
|
| 14 |
with st.spinner("Generating recipe..."):
|
| 15 |
+
api_key = os.environ.get("GROQ_API_KEY")
|
| 16 |
prompt = (
|
| 17 |
f"Write a complete recipe using these ingredients: {ingredients}. "
|
| 18 |
"Include: a creative recipe name, ingredients with amounts, "
|
| 19 |
"numbered cooking steps, and estimated cooking time."
|
| 20 |
)
|
| 21 |
+
response = requests.post(
|
| 22 |
+
"https://api.groq.com/openai/v1/chat/completions",
|
| 23 |
+
headers={"Authorization": f"Bearer {api_key}"},
|
| 24 |
+
json={
|
| 25 |
+
"model": "llama-3.1-8b-instant",
|
| 26 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 27 |
+
"max_tokens": 500,
|
| 28 |
+
"temperature": 0.7,
|
| 29 |
+
},
|
| 30 |
+
timeout=30,
|
| 31 |
)
|
| 32 |
+
response.raise_for_status()
|
| 33 |
+
recipe = response.json()["choices"][0]["message"]["content"]
|
| 34 |
st.success(recipe)
|
| 35 |
else:
|
| 36 |
st.warning("Please enter some ingredients!")
|
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
streamlit>=1.28.0
|
| 2 |
-
|
|
|
|
| 1 |
streamlit>=1.28.0
|
| 2 |
+
requests>=2.31.0
|