BeardedMonster commited on
Commit
e5162e3
·
verified ·
1 Parent(s): 3a6ef57
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
3
  import time
4
- import requests
 
5
  import json
6
 
7
  repo_name = "BeardedMonster/SabiYarn-125M"
@@ -62,18 +63,19 @@ st.write("**Model is running on CPU RAM. So, token generation might be slower (s
62
  st.write("**Avg Response time: 15 secs/ 50 tokens. Response time increase with input length**")
63
  st.write("-" * 50)
64
 
65
- def generate_from_api(user_input, generation_config):
66
- url = " https://pauljeffrey--sabiyarn-fastapi-app.modal.run/predict"
67
-
68
  payload = json.dumps({
69
- "prompt": user_input,
70
- "config": generation_config
71
  })
72
  headers = {
73
- 'Content-Type': 'application/json'
74
  }
75
 
76
- response = requests.request("POST", url, headers=headers, data=payload)
 
77
  return response.json()["generated_text"]
78
 
79
  # Sample texts
@@ -108,7 +110,7 @@ if st.button("Generate"):
108
  try:
109
  st.write("**Generated Text Below:**")
110
  wrapped_input = task_options[task].format(user_input)
111
- generated_text = generate_from_api(wrapped_input, generation_config)
112
  full_output = st.empty()
113
 
114
  start_time = time.time()
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer
3
  import time
4
+ import asyncio
5
+ import httpx
6
  import json
7
 
8
  repo_name = "BeardedMonster/SabiYarn-125M"
 
63
  st.write("**Avg Response time: 15 secs/ 50 tokens. Response time increase with input length**")
64
  st.write("-" * 50)
65
 
66
+ async def generate_from_api(user_input, generation_config):
67
+ url = "https://pauljeffrey--sabiyarn-fastapi-app.modal.run/predict"
68
+
69
  payload = json.dumps({
70
+ "prompt": user_input,
71
+ "config": generation_config
72
  })
73
  headers = {
74
+ 'Content-Type': 'application/json'
75
  }
76
 
77
+ async with httpx.AsyncClient() as client:
78
+ response = await client.post(url, headers=headers, data=payload)
79
  return response.json()["generated_text"]
80
 
81
  # Sample texts
 
110
  try:
111
  st.write("**Generated Text Below:**")
112
  wrapped_input = task_options[task].format(user_input)
113
+ generated_text = asyncio.run(generate_from_api(wrapped_input, generation_config))
114
  full_output = st.empty()
115
 
116
  start_time = time.time()