Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
@author: idoia lerchundi
|
| 3 |
"""
|
| 4 |
import os
|
|
|
|
| 5 |
import streamlit as st
|
| 6 |
from huggingface_hub import InferenceClient
|
| 7 |
import random
|
|
@@ -12,6 +13,17 @@ api_key = os.getenv("HF_TOKEN")
|
|
| 12 |
# Instantiate the InferenceClient
|
| 13 |
client = InferenceClient(api_key=api_key)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Streamlit app title
|
| 16 |
st.title("Text-generation model using Streamlit from Inference API (serverless) feature.")
|
| 17 |
|
|
@@ -23,8 +35,6 @@ if "full_text" not in st.session_state:
|
|
| 23 |
model_options = [ "TinyLlama/TinyLlama-1.1B-Chat-v1.0", "gpt2", "facebook/opt-1.3b", "EleutherAI/gpt-neo-2.7B","meta-llama/Llama-Llama-3-8B-Instruct", "meta-llama/Llama-Llama-3.1-1B-Instruct", "meta-llama/Llama-Llama-3.2-3B-Instruct", "meta-llama/Llama-Llama-3.2-8B-Instruct", "Qwen/Qwen2.5-1.5B-Instruct", "openai-community/gpt2", "google/gemma-1.1-7b-it", "google/gemma-1.27b-it", "google/gemma-1.2b-it", "google/gemma-1.9b-it", "google/gemma-2.2b-it", "HuggingFaceH4/starchat7b-beta", "distilbert/distilgpt2", "facebook/opt-1.3b", "distributed/optimized=gpt2-1b" ]
|
| 24 |
selected_model = st.selectbox("Choose a model:", model_options)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
# Create a text input area for user prompts
|
| 29 |
with st.form("my_form"):
|
| 30 |
text = st.text_area("JOKER (TinyLlama is not great at joke telling.) (using model TinyLlama/TinyLlama-1.1B-Chat-v1.0):", "Tell me a clever and funny joke in exactly 4 sentences. It should make me laugh really hard. Don't repeat the topic in your joke. Be creative and concise.")
|
|
@@ -51,7 +61,9 @@ if submitted:
|
|
| 51 |
top_p=random.uniform(0.7, 1.0),
|
| 52 |
stream=True
|
| 53 |
)
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
# Concatenate chunks to form the full response
|
| 56 |
for chunk in stream:
|
| 57 |
full_text += chunk.choices[0].delta.content
|
|
|
|
| 2 |
@author: idoia lerchundi
|
| 3 |
"""
|
| 4 |
import os
|
| 5 |
+
import time
|
| 6 |
import streamlit as st
|
| 7 |
from huggingface_hub import InferenceClient
|
| 8 |
import random
|
|
|
|
| 13 |
# Instantiate the InferenceClient
|
| 14 |
client = InferenceClient(api_key=api_key)
|
| 15 |
|
| 16 |
+
# Function to simulate some process and return the elapsed time
|
| 17 |
+
def process_with_timing(): start_time = time.time()
|
| 18 |
+
# Simulate a process with sleep
|
| 19 |
+
time.sleep(2.345)
|
| 20 |
+
# Change this value to simulate different processing times
|
| 21 |
+
end_time = time.time()
|
| 22 |
+
elapsed_time = end_time - start_time
|
| 23 |
+
minutes, seconds = divmod(elapsed_time, 60)
|
| 24 |
+
milliseconds = (seconds - int(seconds)) * 1000
|
| 25 |
+
return minutes, int(seconds), milliseconds
|
| 26 |
+
|
| 27 |
# Streamlit app title
|
| 28 |
st.title("Text-generation model using Streamlit from Inference API (serverless) feature.")
|
| 29 |
|
|
|
|
| 35 |
model_options = [ "TinyLlama/TinyLlama-1.1B-Chat-v1.0", "gpt2", "facebook/opt-1.3b", "EleutherAI/gpt-neo-2.7B","meta-llama/Llama-Llama-3-8B-Instruct", "meta-llama/Llama-Llama-3.1-1B-Instruct", "meta-llama/Llama-Llama-3.2-3B-Instruct", "meta-llama/Llama-Llama-3.2-8B-Instruct", "Qwen/Qwen2.5-1.5B-Instruct", "openai-community/gpt2", "google/gemma-1.1-7b-it", "google/gemma-1.27b-it", "google/gemma-1.2b-it", "google/gemma-1.9b-it", "google/gemma-2.2b-it", "HuggingFaceH4/starchat7b-beta", "distilbert/distilgpt2", "facebook/opt-1.3b", "distributed/optimized=gpt2-1b" ]
|
| 36 |
selected_model = st.selectbox("Choose a model:", model_options)
|
| 37 |
|
|
|
|
|
|
|
| 38 |
# Create a text input area for user prompts
|
| 39 |
with st.form("my_form"):
|
| 40 |
text = st.text_area("JOKER (TinyLlama is not great at joke telling.) (using model TinyLlama/TinyLlama-1.1B-Chat-v1.0):", "Tell me a clever and funny joke in exactly 4 sentences. It should make me laugh really hard. Don't repeat the topic in your joke. Be creative and concise.")
|
|
|
|
| 61 |
top_p=random.uniform(0.7, 1.0),
|
| 62 |
stream=True
|
| 63 |
)
|
| 64 |
+
minutes, seconds, milliseconds = process_with_timing()
|
| 65 |
+
st.write(f"Elapsed Time: {int(minutes)} minutes, {seconds} seconds, and {milliseconds:.2f} milliseconds")
|
| 66 |
+
|
| 67 |
# Concatenate chunks to form the full response
|
| 68 |
for chunk in stream:
|
| 69 |
full_text += chunk.choices[0].delta.content
|