Spaces:
Sleeping
Sleeping
Back to InferenceClient with Mixtral-8x7B
Browse files- app.py +14 -13
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,35 +1,36 @@
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
ingredients = st.text_input("Enter ingredients (comma-separated):", placeholder="eggs, cheese, spinach")
|
| 13 |
|
| 14 |
if st.button("Generate Recipe"):
|
| 15 |
if ingredients:
|
| 16 |
with st.spinner("Generating recipe..."):
|
| 17 |
-
token = os.environ.get("HF_TOKEN")
|
| 18 |
-
headers = {"Authorization": f"Bearer {token}"}
|
| 19 |
prompt = (
|
| 20 |
f"Write a complete recipe using these ingredients: {ingredients}. "
|
| 21 |
"Include: a creative recipe name, ingredients with amounts, "
|
| 22 |
"numbered cooking steps, and estimated cooking time."
|
| 23 |
)
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
response.raise_for_status()
|
| 32 |
-
recipe = response.json()["choices"][0]["message"]["content"]
|
| 33 |
st.success(recipe)
|
| 34 |
else:
|
| 35 |
st.warning("Please enter some ingredients!")
|
|
|
|
| 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(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 = client.chat_completion(
|
| 28 |
+
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 29 |
+
messages=[{"role": "user", "content": prompt}],
|
| 30 |
+
max_tokens=500,
|
| 31 |
+
temperature=0.7,
|
| 32 |
+
)
|
| 33 |
+
recipe = response.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 |
+
huggingface_hub>=0.23.0
|