added inf
Browse files
app.py
CHANGED
@@ -1,11 +1,17 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
-
from huggingface_hub import login
|
4 |
from PIL import Image
|
5 |
import os
|
6 |
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
login(token=os.getenv("HUGGINGFACE_TOKEN"))
|
|
|
9 |
|
10 |
st.header("Character Captions (IN PROGRESS!)")
|
11 |
st.write("Have a character caption any image you upload!")
|
@@ -38,12 +44,28 @@ if uploaded_img is not None:
|
|
38 |
prompt = character_prompts[personality]
|
39 |
|
40 |
|
|
|
|
|
|
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
generated_text = text_generator(prompt, max_length=50, do_sample=True)
|
48 |
-
styled_caption = generated_text[0]['generated_text']
|
49 |
-
st.write("Character-Styled Caption:", styled_caption)
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
from huggingface_hub import login, InferenceClient
|
4 |
from PIL import Image
|
5 |
import os
|
6 |
|
7 |
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
login(token=os.getenv("HUGGINGFACE_TOKEN"))
|
14 |
+
client = InferenceClient(api_key="HUGGINGFACE_TOKEN")
|
15 |
|
16 |
st.header("Character Captions (IN PROGRESS!)")
|
17 |
st.write("Have a character caption any image you upload!")
|
|
|
44 |
prompt = character_prompts[personality]
|
45 |
|
46 |
|
47 |
+
messages = [
|
48 |
+
{ "role": "user", "content": prompt }
|
49 |
+
]
|
50 |
|
51 |
+
stream = client.chat.completions.create(
|
52 |
+
model="meta-llama/Llama-3.2-3B-Instruct",
|
53 |
+
messages=messages,
|
54 |
+
max_tokens=500,
|
55 |
+
stream=True
|
56 |
+
)
|
57 |
|
58 |
+
for chunk in stream:
|
59 |
+
st.write(chunk.choices[0].delta.content)
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
# text_generator = pipeline("text-generation", model="meta-llama/Llama-2-7b-hf", framework="pt")
|
65 |
+
|
66 |
+
# prompt = character_prompts[character]
|
67 |
+
# st.write("Styled Prompt:", prompt)
|
68 |
|
69 |
+
# generated_text = text_generator(prompt, max_length=50, do_sample=True)
|
70 |
+
# styled_caption = generated_text[0]['generated_text']
|
71 |
+
# st.write("Character-Styled Caption:", styled_caption)
|