3v324v23 commited on
Commit
1ff9bc2
·
1 Parent(s): f8ca1c6

Switch to Groq API with llama-3.1-8b-instant

Browse files
Files changed (2) hide show
  1. app.py +14 -14
  2. 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 = client.chat_completion(
28
- model="meta-llama/Llama-3.2-3B-Instruct",
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!")
 
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
- huggingface_hub>=0.23.0
 
1
  streamlit>=1.28.0
2
+ requests>=2.31.0