Spaces:
Running
Running
import requests | |
API_URL = "http://127.0.0.1:5000/api/process" | |
def save_to_file(user_input): | |
with open("user_input.txt", "w") as file: | |
file.write(user_input) | |
def send_msg_to_server(input_text): | |
try: | |
# 构造请求数据 | |
payload = {"text": input_text} | |
headers = {"Content-Type": "application/json"} | |
# 发送请求 | |
response = requests.post(API_URL, json=payload, headers=headers) | |
response.raise_for_status() # 检查是否请求成功 | |
# 返回响应结果 | |
result = response.json() # 假设服务器返回的是 JSON 格式 | |
return result.get("processed_text", "No result returned.") | |
except requests.RequestException as e: | |
return f"请求失败:{e}" |