BeardedMonster commited on
Commit
2e7d8ed
·
verified ·
1 Parent(s): a7b2902
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig #, TextIteratorStreamer
3
  import torch
4
  import time
 
5
 
6
  # from threading import Thread
7
 
@@ -89,6 +90,9 @@ def generate_and_stream_text(input_ids, generation_config):
89
  return generated_text
90
 
91
 
 
 
 
92
  # Text input
93
  user_input = st.text_area("Enter text below (please, first read the instructions on how to use in the side bar): ", "<prompt> Tell me a story in pidgin <response>:")
94
 
@@ -97,7 +101,7 @@ if st.button("Generate"):
97
  if user_input:
98
  try:
99
  st.write("**Generated Text Below:**")
100
- input_ids = tokenizer(user_input, return_tensors="pt")["input_ids"].to(device)
101
  full_output = st.empty()
102
 
103
  # # Run the generation in a separate thread, so that we can fetch the generated text in a non-blocking way.
@@ -110,7 +114,8 @@ if st.button("Generate"):
110
  # full_output.text(generated_text)
111
  # def stream_text():
112
  start_time = time.time()
113
- generated_text = generate_and_stream_text(input_ids, generation_config)
 
114
  end_time = time.time()
115
  # Style definition directly within full_output.text()
116
  # full_output.text("""<div style="width: 100%; height: 300px; overflow-y: auto; border: 1px solid #ddd; padding: 10px;">""")
 
2
  from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig #, TextIteratorStreamer
3
  import torch
4
  import time
5
+ import requests
6
 
7
  # from threading import Thread
8
 
 
90
  return generated_text
91
 
92
 
93
+ def generate_from_api(user_input, generation_config):
94
+ return requests.post('https://pauljeffrey--sabiyarn-fastapi-app.modal.run/predict', data={"prompt": user_input, "config": generation_config} )
95
+
96
  # Text input
97
  user_input = st.text_area("Enter text below (please, first read the instructions on how to use in the side bar): ", "<prompt> Tell me a story in pidgin <response>:")
98
 
 
101
  if user_input:
102
  try:
103
  st.write("**Generated Text Below:**")
104
+ # input_ids = tokenizer(user_input, return_tensors="pt")["input_ids"].to(device)
105
  full_output = st.empty()
106
 
107
  # # Run the generation in a separate thread, so that we can fetch the generated text in a non-blocking way.
 
114
  # full_output.text(generated_text)
115
  # def stream_text():
116
  start_time = time.time()
117
+ # generated_text = generate_and_stream_text(input_ids, generation_config
118
+ generated_text = generate_from_api(user_input, generation_config)
119
  end_time = time.time()
120
  # Style definition directly within full_output.text()
121
  # full_output.text("""<div style="width: 100%; height: 300px; overflow-y: auto; border: 1px solid #ddd; padding: 10px;">""")