mostafa-atef21 commited on
Commit
361df8a
·
1 Parent(s): e376a86

add app and req

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import ViTImageProcessor, ViTForImageClassification
2
+ from PIL import Image
3
+ import streamlit as st
4
+ from groq import Groq
5
+
6
+ client = Groq(
7
+ api_key="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",
8
+ )
9
+
10
+ # Streamlit app title
11
+ st.title("Product Detection App")
12
+
13
+ # File uploader for image input
14
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
15
+
16
+ if uploaded_file is not None:
17
+ image = Image.open(uploaded_file)
18
+
19
+ # Process the image and make predictions
20
+ inputs = processor(images=image, return_tensors="pt")
21
+ outputs = model(**inputs)
22
+ logits = outputs.logits
23
+ predicted_class_idx = logits.argmax(-1).item()
24
+ predicted_class = model.config.id2label[predicted_class_idx]
25
+
26
+ # Display the predicted class
27
+ st.write(f"Predicted Class: {predicted_class}")
28
+
29
+ # Generate keywords using Groq
30
+ chat_completion = client.chat.completions.create(
31
+ messages=[
32
+ {
33
+ "role": "user",
34
+ "content": f"Generate a comma separated list of high-converting keywords for selling a {predicted_class}.",
35
+ }
36
+ ],
37
+ model="llama3-8b-8192",
38
+ )
39
+
40
+ # Display the generated keywords
41
+ st.write("Generated Keywords:")
42
+ st.write(chat_completion.choices[0].message.content)
43
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ Pillow
3
+ streamlit
4
+ groq