AItool commited on
Commit
5b7582d
·
verified ·
1 Parent(s): 5ac81fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -13,18 +13,6 @@ api_key = os.getenv("HF_TOKEN")
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():
18
- start_time = time.time()
19
- # Simulate a process with sleep
20
- #time.sleep(2.345)
21
- # Change this value to simulate different processing times
22
- end_time = time.time()
23
- elapsed_time = end_time - start_time
24
- minutes, seconds = divmod(elapsed_time, 60)
25
- milliseconds = (seconds - int(seconds)) * 1000
26
- return minutes, int(seconds), milliseconds
27
-
28
  # Streamlit app title
29
  st.title("Text-generation model using Streamlit from Inference API (serverless) feature.")
30
 
@@ -51,10 +39,10 @@ if submitted:
51
  messages = [
52
  {"role": "user", "content": text}
53
  ]
54
-
55
- # Call the function to get the elapsed time
56
- minutes, seconds, milliseconds = process_with_timing()
57
-
58
  # Create a new stream for each submission
59
  stream = client.chat.completions.create(
60
  model=selected_model,
@@ -70,7 +58,15 @@ if submitted:
70
  # Concatenate chunks to form the full response
71
  for chunk in stream:
72
  full_text += chunk.choices[0].delta.content
73
-
 
 
 
 
 
 
 
 
74
  # Update session state with the full response
75
  st.session_state["full_text"] = full_text
76
 
 
13
  # Instantiate the InferenceClient
14
  client = InferenceClient(api_key=api_key)
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Streamlit app title
17
  st.title("Text-generation model using Streamlit from Inference API (serverless) feature.")
18
 
 
39
  messages = [
40
  {"role": "user", "content": text}
41
  ]
42
+
43
+ # Start timing
44
+ start_time = time.time()
45
+
46
  # Create a new stream for each submission
47
  stream = client.chat.completions.create(
48
  model=selected_model,
 
58
  # Concatenate chunks to form the full response
59
  for chunk in stream:
60
  full_text += chunk.choices[0].delta.content
61
+
62
+ # End timing
63
+ end_time = time.time()
64
+ elapsed_time = end_time - start_time
65
+
66
+ # Calculate minutes, seconds, and milliseconds
67
+ minutes, seconds = divmod(elapsed_time, 60)
68
+ milliseconds = (seconds - int(seconds)) * 1000
69
+
70
  # Update session state with the full response
71
  st.session_state["full_text"] = full_text
72