Spaces:
Running
Running
Llama deleted
Browse files
app.py
CHANGED
@@ -53,51 +53,3 @@ async def face_analyse(file: UploadFile = File(...)):
|
|
53 |
# Assuming categories is a list of category labels
|
54 |
return dict(zip(categories, map(float, probs)))
|
55 |
|
56 |
-
# Initialize the Meta-Llama-3-8B-Instruct pipeline
|
57 |
-
llama_model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
58 |
-
llama_pipeline = pipeline(
|
59 |
-
"text-generation",
|
60 |
-
model=llama_model_id,
|
61 |
-
model_kwargs={"torch_dtype": torch.bfloat16},
|
62 |
-
device_map="auto",
|
63 |
-
auth_token=access_token
|
64 |
-
)
|
65 |
-
|
66 |
-
|
67 |
-
@app.post("/frame-details")
|
68 |
-
def frame_details(text: str):
|
69 |
-
|
70 |
-
# Extract structured information from a given text about frames using the Meta-Llama-3-8B-Instruct model. The model will output details like price, color, etc.
|
71 |
-
|
72 |
-
messages = [
|
73 |
-
{"role": "system", "content": "You are an api chatbot for frames and glasses who always responds with only a json. Extract the infomation given into a structured json for frame details"},
|
74 |
-
{"role": "user", "content": text},
|
75 |
-
]
|
76 |
-
|
77 |
-
terminators = [
|
78 |
-
llama_pipeline.tokenizer.eos_token_id,
|
79 |
-
llama_pipeline.tokenizer.convert_tokens_to_ids("")
|
80 |
-
]
|
81 |
-
|
82 |
-
outputs = llama_pipeline(
|
83 |
-
messages,
|
84 |
-
max_new_tokens=256,
|
85 |
-
eos_token_id=terminators,
|
86 |
-
do_sample=True,
|
87 |
-
temperature=0.6,
|
88 |
-
top_p=0.9,
|
89 |
-
)
|
90 |
-
|
91 |
-
# Extract the last generated text from the output
|
92 |
-
generated_text = outputs[0]["generated_text"]
|
93 |
-
|
94 |
-
# Parse the generated text to extract structured information (this is an example and should be customized)
|
95 |
-
# Here, you would add your own logic to parse the generated text
|
96 |
-
# For now, we'll assume the generated text is in JSON format
|
97 |
-
try:
|
98 |
-
extracted_info = eval(generated_text) # It's recommended to use `json.loads` in a real application
|
99 |
-
except Exception as e:
|
100 |
-
return {"error": "Failed to parse the generated text."}
|
101 |
-
|
102 |
-
return extracted_info
|
103 |
-
|
|
|
53 |
# Assuming categories is a list of category labels
|
54 |
return dict(zip(categories, map(float, probs)))
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|