Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .env.gpg +0 -0
- app.py +37 -2
- requirements.txt +2 -0
.env.gpg
ADDED
|
Binary file (298 Bytes). View file
|
|
|
app.py
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
|
|
| 1 |
from typing import List, Optional
|
| 2 |
import gradio as gr
|
| 3 |
from dotenv import load_dotenv
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from openai import OpenAI
|
| 6 |
-
import
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
|
|
|
|
|
|
|
| 10 |
QUERY = """
|
| 11 |
extract all singular ingredients from the provided ingredient string.
|
| 12 |
While doing so, shorten the ingredient name to only the essential part.
|
|
@@ -43,7 +47,7 @@ class Ingredients(BaseModel):
|
|
| 43 |
# client = instructor.from_openai(OpenAI(), mode=instructor.Mode.JSON)
|
| 44 |
|
| 45 |
|
| 46 |
-
def predict(ingredients: str, openai_key: str) -> Ingredients:
|
| 47 |
"""
|
| 48 |
Predicts the ingredients using a GPT-3.5-turbo model.
|
| 49 |
|
|
@@ -54,6 +58,23 @@ def predict(ingredients: str, openai_key: str) -> Ingredients:
|
|
| 54 |
Ingredients: The parsed ingredients in the form of an Ingredients object.
|
| 55 |
"""
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
client = OpenAI(api_key=openai_key)
|
| 58 |
|
| 59 |
return (
|
|
@@ -81,5 +102,19 @@ demo = gr.Interface(
|
|
| 81 |
fn=predict,
|
| 82 |
inputs=["text", gr.Text(label="OpenAI API Key", type="password")],
|
| 83 |
outputs="json",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
)
|
| 85 |
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
from typing import List, Optional
|
| 3 |
import gradio as gr
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
+
import instructor
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from openai import OpenAI
|
| 8 |
+
from groq import Groq
|
| 9 |
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
+
groq_client = instructor.from_groq(Groq(), mode=instructor.Mode.JSON)
|
| 13 |
+
|
| 14 |
QUERY = """
|
| 15 |
extract all singular ingredients from the provided ingredient string.
|
| 16 |
While doing so, shorten the ingredient name to only the essential part.
|
|
|
|
| 47 |
# client = instructor.from_openai(OpenAI(), mode=instructor.Mode.JSON)
|
| 48 |
|
| 49 |
|
| 50 |
+
def predict(ingredients: str, openai_key: str = "") -> Ingredients:
|
| 51 |
"""
|
| 52 |
Predicts the ingredients using a GPT-3.5-turbo model.
|
| 53 |
|
|
|
|
| 58 |
Ingredients: The parsed ingredients in the form of an Ingredients object.
|
| 59 |
"""
|
| 60 |
|
| 61 |
+
if openai_key == "":
|
| 62 |
+
return groq_client.chat.completions.create(
|
| 63 |
+
model="llama-3.1-70b-versatile",
|
| 64 |
+
messages=[
|
| 65 |
+
{
|
| 66 |
+
"role": "user",
|
| 67 |
+
"content": f"""
|
| 68 |
+
{QUERY}
|
| 69 |
+
{ingredients}
|
| 70 |
+
{STIMULI}
|
| 71 |
+
""",
|
| 72 |
+
},
|
| 73 |
+
],
|
| 74 |
+
response_model=Ingredients,
|
| 75 |
+
temperature=0.0,
|
| 76 |
+
).model_dump_json(exclude_unset=True, exclude_none=True)
|
| 77 |
+
|
| 78 |
client = OpenAI(api_key=openai_key)
|
| 79 |
|
| 80 |
return (
|
|
|
|
| 102 |
fn=predict,
|
| 103 |
inputs=["text", gr.Text(label="OpenAI API Key", type="password")],
|
| 104 |
outputs="json",
|
| 105 |
+
examples=[
|
| 106 |
+
[
|
| 107 |
+
"97,2 % DINKELVOLLKORNMEHL, GERSTENMALZMEHL, Salz",
|
| 108 |
+
"",
|
| 109 |
+
],
|
| 110 |
+
[
|
| 111 |
+
"BIO Grüne Linsen. Grüne Linsen aus kontrolliert biologischem Anbau. Kühl bei unter +30°C lagern. Nicht-EU-Landwirtschaft.",
|
| 112 |
+
"",
|
| 113 |
+
],
|
| 114 |
+
[
|
| 115 |
+
"Milchschokoladenkuvertüre, Kakao: 40,5% mindestens. Zucker, Kakaobutter, VOLLMILCHPULVER, Kakaomasse (Ghana), Emulgator: SOJALECITHIN, natürliches Vanillepulver. Trocken und kühl bei +17°C bis +18°C lagern. Eigenschaften: Eiweiß aus tierischer Milch.",
|
| 116 |
+
"",
|
| 117 |
+
],
|
| 118 |
+
],
|
| 119 |
)
|
| 120 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
openai
|
| 2 |
pydantic
|
|
|
|
|
|
|
|
|
| 1 |
openai
|
| 2 |
pydantic
|
| 3 |
+
dotenv
|
| 4 |
+
groq
|