Spaces:
Build error
Build error
naourpally
commited on
Commit
·
e47edb7
1
Parent(s):
a2ff132
Import json
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import requests
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
def get_text_response(prompt):
|
| 5 |
api_url = "http://35.233.231.20:5002/api/generate"
|
|
@@ -8,6 +9,7 @@ def get_text_response(prompt):
|
|
| 8 |
"prompt": prompt,
|
| 9 |
"stream": True
|
| 10 |
}
|
|
|
|
| 11 |
with requests.post(api_url, json=data_payload, stream=True) as response:
|
| 12 |
for line in response.iter_lines():
|
| 13 |
if line:
|
|
@@ -17,7 +19,8 @@ def get_text_response(prompt):
|
|
| 17 |
response_json = json.loads(json_line)
|
| 18 |
text_response = response_json.get("response", "")
|
| 19 |
done = response_json.get("done", False)
|
| 20 |
-
|
|
|
|
| 21 |
if done:
|
| 22 |
break
|
| 23 |
except json.JSONDecodeError as e:
|
|
|
|
| 1 |
import requests
|
| 2 |
import gradio as gr
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
def get_text_response(prompt):
|
| 6 |
api_url = "http://35.233.231.20:5002/api/generate"
|
|
|
|
| 9 |
"prompt": prompt,
|
| 10 |
"stream": True
|
| 11 |
}
|
| 12 |
+
full_response = "" # Initialize an empty string to hold the full response
|
| 13 |
with requests.post(api_url, json=data_payload, stream=True) as response:
|
| 14 |
for line in response.iter_lines():
|
| 15 |
if line:
|
|
|
|
| 19 |
response_json = json.loads(json_line)
|
| 20 |
text_response = response_json.get("response", "")
|
| 21 |
done = response_json.get("done", False)
|
| 22 |
+
full_response += text_response # Concatenate the new response
|
| 23 |
+
yield full_response # Yield the full response so far
|
| 24 |
if done:
|
| 25 |
break
|
| 26 |
except json.JSONDecodeError as e:
|